From 4b2e5216ff9747e093c4ddfe22ed955bfce7aa78 Mon Sep 17 00:00:00 2001 From: Zachary Norman Date: Fri, 14 Jul 2023 13:05:31 -0600 Subject: [PATCH] Tweak logs --- .../src/lib/helpers/add-history-input.ts | 10 +++++++ .../debug/src/lib/helpers/add-history.ts | 26 +++++++++++++++++++ .../vscode/debug/src/lib/helpers/log-input.ts | 22 +++------------- .../debug/src/lib/helpers/log-output.ts | 21 +++------------ .../src/lib/helpers/log-session-start.ts | 22 +++------------- .../debug/src/lib/helpers/log-session-stop.ts | 23 +++------------- 6 files changed, 52 insertions(+), 72 deletions(-) create mode 100644 libs/vscode/debug/src/lib/helpers/add-history-input.ts create mode 100644 libs/vscode/debug/src/lib/helpers/add-history.ts diff --git a/libs/vscode/debug/src/lib/helpers/add-history-input.ts b/libs/vscode/debug/src/lib/helpers/add-history-input.ts new file mode 100644 index 000000000..c7417506e --- /dev/null +++ b/libs/vscode/debug/src/lib/helpers/add-history-input.ts @@ -0,0 +1,10 @@ +import { platform } from 'os'; + +import { AddHistory } from './add-history'; + +/** + * Adds input to the history file as a new entry/line + */ +export function AddHistoryInput(content: string) { + AddHistory(platform() === 'win32' ? `\n${content}\n` : `\n\n${content}\n`); +} diff --git a/libs/vscode/debug/src/lib/helpers/add-history.ts b/libs/vscode/debug/src/lib/helpers/add-history.ts new file mode 100644 index 000000000..66184f673 --- /dev/null +++ b/libs/vscode/debug/src/lib/helpers/add-history.ts @@ -0,0 +1,26 @@ +import { IDL_DEBUG_ADAPTER_LOG } from '@idl/logger'; +import { IDL_TRANSLATION } from '@idl/translation'; +import { IDL_LOGGER } from '@idl/vscode/client'; +import { appendFileSync } from 'fs'; + +import { OUTPUT_CONFIG } from './log-output'; + +/** + * Adds text to our history file as raw text + */ +export function AddHistory(content: string) { + // check if we need to write to our log file + if (OUTPUT_CONFIG.FILE !== '') { + try { + appendFileSync(OUTPUT_CONFIG.FILE, content); + } catch (err) { + IDL_LOGGER.log({ + type: 'error', + log: IDL_DEBUG_ADAPTER_LOG, + content: [IDL_TRANSLATION.debugger.errors.addHistory, err], + alert: IDL_TRANSLATION.debugger.errors.addHistory, + }); + OUTPUT_CONFIG.FILE = ''; + } + } +} diff --git a/libs/vscode/debug/src/lib/helpers/log-input.ts b/libs/vscode/debug/src/lib/helpers/log-input.ts index 7b8beda5d..dc5892259 100644 --- a/libs/vscode/debug/src/lib/helpers/log-input.ts +++ b/libs/vscode/debug/src/lib/helpers/log-input.ts @@ -1,9 +1,7 @@ import { REGEX_NEW_LINE } from '@idl/idl'; -import { IDL_DEBUG_ADAPTER_LOG } from '@idl/logger'; -import { IDL_TRANSLATION } from '@idl/translation'; -import { IDL_DEBUG_OUTPUT_CHANNEL, IDL_LOGGER } from '@idl/vscode/client'; -import { appendFileSync } from 'fs'; +import { IDL_DEBUG_OUTPUT_CHANNEL } from '@idl/vscode/client'; +import { AddHistoryInput } from './add-history-input'; import { OUTPUT_CONFIG } from './log-output'; /** @@ -20,18 +18,6 @@ export function LogInput(code: string) { IDL_DEBUG_OUTPUT_CHANNEL.appendLine(''); IDL_DEBUG_OUTPUT_CHANNEL.appendLine(toWrite); - // check if we need to write to our log file - if (OUTPUT_CONFIG.FILE !== '') { - try { - appendFileSync(OUTPUT_CONFIG.FILE, `\n\n${toWrite}\n`); - } catch (err) { - IDL_LOGGER.log({ - type: 'error', - log: IDL_DEBUG_ADAPTER_LOG, - content: [IDL_TRANSLATION.debugger.errors.addHistory, err], - alert: IDL_TRANSLATION.debugger.errors.addHistory, - }); - OUTPUT_CONFIG.FILE = ''; - } - } + // write to our fil eon disk + AddHistoryInput(toWrite); } diff --git a/libs/vscode/debug/src/lib/helpers/log-output.ts b/libs/vscode/debug/src/lib/helpers/log-output.ts index e800d7ef0..65cc7334d 100644 --- a/libs/vscode/debug/src/lib/helpers/log-output.ts +++ b/libs/vscode/debug/src/lib/helpers/log-output.ts @@ -1,8 +1,7 @@ import { REGEX_NEW_LINE } from '@idl/idl'; -import { IDL_DEBUG_ADAPTER_LOG } from '@idl/logger'; -import { IDL_TRANSLATION } from '@idl/translation'; -import { IDL_DEBUG_OUTPUT_CHANNEL, IDL_LOGGER } from '@idl/vscode/client'; -import { appendFileSync } from 'fs'; +import { IDL_DEBUG_OUTPUT_CHANNEL } from '@idl/vscode/client'; + +import { AddHistory } from './add-history'; /** * Config for the output @@ -35,17 +34,5 @@ export function LogOutput(content: string) { } // check if we need to write to our log file - if (OUTPUT_CONFIG.FILE !== '') { - try { - appendFileSync(OUTPUT_CONFIG.FILE, toWrite); - } catch (err) { - IDL_LOGGER.log({ - type: 'error', - log: IDL_DEBUG_ADAPTER_LOG, - content: [IDL_TRANSLATION.debugger.errors.addHistory, err], - alert: IDL_TRANSLATION.debugger.errors.addHistory, - }); - OUTPUT_CONFIG.FILE = ''; - } - } + AddHistory(toWrite); } diff --git a/libs/vscode/debug/src/lib/helpers/log-session-start.ts b/libs/vscode/debug/src/lib/helpers/log-session-start.ts index 34becdf95..cb16ec664 100644 --- a/libs/vscode/debug/src/lib/helpers/log-session-start.ts +++ b/libs/vscode/debug/src/lib/helpers/log-session-start.ts @@ -1,8 +1,6 @@ -import { IDL_DEBUG_ADAPTER_LOG } from '@idl/logger'; -import { IDL_TRANSLATION } from '@idl/translation'; -import { IDL_DEBUG_OUTPUT_CHANNEL, IDL_LOGGER } from '@idl/vscode/client'; -import { appendFileSync } from 'fs'; +import { IDL_DEBUG_OUTPUT_CHANNEL } from '@idl/vscode/client'; +import { AddHistoryInput } from './add-history-input'; import { CreateHistoryFile } from './create-history-file'; import { OUTPUT_CONFIG } from './log-output'; @@ -23,18 +21,6 @@ export function LogSessionStart() { IDL_DEBUG_OUTPUT_CHANNEL.appendLine(toWrite); - // check if we need to write to our log file - if (OUTPUT_CONFIG.FILE !== '') { - try { - appendFileSync(OUTPUT_CONFIG.FILE, `\n${toWrite}\n`); - } catch (err) { - IDL_LOGGER.log({ - type: 'error', - log: IDL_DEBUG_ADAPTER_LOG, - content: [IDL_TRANSLATION.debugger.errors.addHistory, err], - alert: IDL_TRANSLATION.debugger.errors.addHistory, - }); - OUTPUT_CONFIG.FILE = ''; - } - } + // write to our fil eon disk + AddHistoryInput(toWrite); } diff --git a/libs/vscode/debug/src/lib/helpers/log-session-stop.ts b/libs/vscode/debug/src/lib/helpers/log-session-stop.ts index a6958408f..786899ea4 100644 --- a/libs/vscode/debug/src/lib/helpers/log-session-stop.ts +++ b/libs/vscode/debug/src/lib/helpers/log-session-stop.ts @@ -1,9 +1,6 @@ -import { IDL_DEBUG_ADAPTER_LOG } from '@idl/logger'; -import { IDL_TRANSLATION } from '@idl/translation'; -import { IDL_DEBUG_OUTPUT_CHANNEL, IDL_LOGGER } from '@idl/vscode/client'; -import { appendFileSync } from 'fs'; +import { IDL_DEBUG_OUTPUT_CHANNEL } from '@idl/vscode/client'; -import { OUTPUT_CONFIG } from './log-output'; +import { AddHistoryInput } from './add-history-input'; /** * Logs that a session has stopped @@ -14,18 +11,6 @@ export function LogSessionStop(reason: string) { IDL_DEBUG_OUTPUT_CHANNEL.appendLine(''); IDL_DEBUG_OUTPUT_CHANNEL.appendLine(toWrite); - // check if we need to write to our log file - if (OUTPUT_CONFIG.FILE !== '') { - try { - appendFileSync(OUTPUT_CONFIG.FILE, `\n\n${toWrite}\n`); - } catch (err) { - IDL_LOGGER.log({ - type: 'error', - log: IDL_DEBUG_ADAPTER_LOG, - content: [IDL_TRANSLATION.debugger.errors.addHistory, err], - alert: IDL_TRANSLATION.debugger.errors.addHistory, - }); - OUTPUT_CONFIG.FILE = ''; - } - } + // log to our file + AddHistoryInput(toWrite); }