Skip to content

Commit

Permalink
Tweak logs
Browse files Browse the repository at this point in the history
  • Loading branch information
znorman-harris committed Jul 14, 2023
1 parent 356c5d1 commit 4b2e521
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 72 deletions.
10 changes: 10 additions & 0 deletions libs/vscode/debug/src/lib/helpers/add-history-input.ts
Original file line number Diff line number Diff line change
@@ -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`);
}
26 changes: 26 additions & 0 deletions libs/vscode/debug/src/lib/helpers/add-history.ts
Original file line number Diff line number Diff line change
@@ -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 = '';
}
}
}
22 changes: 4 additions & 18 deletions libs/vscode/debug/src/lib/helpers/log-input.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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);
}
21 changes: 4 additions & 17 deletions libs/vscode/debug/src/lib/helpers/log-output.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
22 changes: 4 additions & 18 deletions libs/vscode/debug/src/lib/helpers/log-session-start.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
}
23 changes: 4 additions & 19 deletions libs/vscode/debug/src/lib/helpers/log-session-stop.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

0 comments on commit 4b2e521

Please sign in to comment.