Skip to content

Commit

Permalink
Tweak formatting for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
znorman-harris committed Jul 14, 2023
1 parent b4d79ae commit 356c5d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
26 changes: 22 additions & 4 deletions libs/vscode/debug/src/lib/helpers/log-input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { REGEX_NEW_LINE } from '@idl/idl';
import { IDL_DEBUG_OUTPUT_CHANNEL } from '@idl/vscode/client';
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 { OUTPUT_CONFIG } from './log-output';

Expand All @@ -10,10 +13,25 @@ export function LogInput(code: string) {
// update flag that we have first input
OUTPUT_CONFIG.FIRST = true;

const toWrite = `idl input ${code.replace(REGEX_NEW_LINE, '\n ')}`;

// append new line
IDL_DEBUG_OUTPUT_CHANNEL.appendLine('');
IDL_DEBUG_OUTPUT_CHANNEL.appendLine('');
IDL_DEBUG_OUTPUT_CHANNEL.appendLine(
`idl input ${code.replace(REGEX_NEW_LINE, '\n ')}`
);
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 = '';
}
}
}
26 changes: 22 additions & 4 deletions libs/vscode/debug/src/lib/helpers/log-session-start.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { IDL_DEBUG_OUTPUT_CHANNEL } from '@idl/vscode/client';
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 { CreateHistoryFile } from './create-history-file';
import { OUTPUT_CONFIG } from './log-output';
Expand All @@ -16,7 +19,22 @@ export function LogSessionStart() {
// make our log file (indicates which file we use for input/output)
CreateHistoryFile();

IDL_DEBUG_OUTPUT_CHANNEL.appendLine(
`idl started ${new Date().toISOString()}`
);
const toWrite = `idl started ${new Date().toISOString()}`;

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 = '';
}
}
}
5 changes: 3 additions & 2 deletions libs/vscode/debug/src/lib/helpers/log-session-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { OUTPUT_CONFIG } from './log-output';
* Logs that a session has stopped
*/
export function LogSessionStop(reason: string) {
const toWrite = `\nidl ${reason} ${new Date().toISOString()}`;
const toWrite = `idl ${reason} ${new Date().toISOString()}`;
IDL_DEBUG_OUTPUT_CHANNEL.appendLine('');
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, toWrite);
appendFileSync(OUTPUT_CONFIG.FILE, `\n\n${toWrite}\n`);
} catch (err) {
IDL_LOGGER.log({
type: 'error',
Expand Down

0 comments on commit 356c5d1

Please sign in to comment.