Skip to content

Commit

Permalink
prefix timestamps on VSCode logger as well
Browse files Browse the repository at this point in the history
  • Loading branch information
haneefdm committed Aug 23, 2023
1 parent 98f8622 commit b74c8b1
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ class CustomContinuedEvent extends Event implements DebugProtocol.Event {
}

const traceThreads = false;

export class GDBDebugSession extends LoggingDebugSession {
private server: GDBServer;
public args: ConfigurationArguments;
Expand Down Expand Up @@ -327,19 +326,26 @@ export class GDBDebugSession extends LoggingDebugSession {
this.sendResponse(response);
}

private setupLogger(enable: boolean, args: ConfigurationArguments) {
const level = enable && (args.pvtShowDevDebugOutput === ADAPTER_DEBUG_MODE.VSCODE) ? Logger.LogLevel.Verbose : Logger.LogLevel.Stop;
const showTimes = (enable && (args.pvtShowDevDebugOutput === ADAPTER_DEBUG_MODE.VSCODE)) && args.showDevDebugTimestamps;
logger.setup(level, false, showTimes);
}
private launchAttachInit(args: ConfigurationArguments) {
// make sure to 'Stop' the buffered logging if 'trace' is not set
args.pvtShowDevDebugOutput = args.showDevDebugOutput;
this.setupLogger(true, args);
if (args.showDevDebugOutput === ADAPTER_DEBUG_MODE.VSCODE) {
logger.setup(Logger.LogLevel.Verbose , false, false);
args.showDevDebugOutput = ADAPTER_DEBUG_MODE.RAW;
}

if (args.pvtShowDevDebugOutput === ADAPTER_DEBUG_MODE.VSCODE) {
logger.init((ev: OutputEvent) => {
// This callback is called with every msg. We don't want to create a recursive
// callback to output a single message. Turn off logging, print and then turn it
// back on.
logger.setup(Logger.LogLevel.Stop, false, false);
const msg = this.wrapTimeStamp(ev.body.output);
this.sendEvent(new OutputEvent(msg, ev.body.category));
logger.setup(Logger.LogLevel.Verbose, false, false);
});
}

this.args = this.normalizeArguments(args);
this.handleMsg('stdout',
`Cortex-Debug: VSCode debugger extension version ${args.pvtVersion} git(${__COMMIT_HASH__}). ` +
Expand Down Expand Up @@ -1624,14 +1630,18 @@ export class GDBDebugSession extends LoggingDebugSession {
protected timeStart = Date.now();
protected wrapTimeStamp(str: string): string {
if (this.args.showDevDebugOutput && this.args.showDevDebugTimestamps) {
const elapsed = Date.now() - this.timeStart;
const elapsedStr = elapsed.toString().padStart(10, '0');
return elapsedStr + ': ' + str;
return this.wrapTimeStampRaw(str);
} else {
return str;
}
}

private wrapTimeStampRaw(str: string) {
const elapsed = Date.now() - this.timeStart;
const elapsedStr = elapsed.toString().padStart(10, '0');
return elapsedStr + ': ' + str;
}

private serverControllerEvent(event: DebugProtocol.Event) {
this.sendEvent(event);
}
Expand All @@ -1645,15 +1655,7 @@ export class GDBDebugSession extends LoggingDebugSession {
}
if (type === 'target') { type = 'stdout'; }
if (type === 'log') { type = 'stderr'; }
msg = this.wrapTimeStamp(msg);
if (this.args.pvtShowDevDebugOutput === ADAPTER_DEBUG_MODE.VSCODE) {
// Suppress output prevents so it does not flood the Debug Console with duplicate stuff.
this.setupLogger(false, this.args);
this.sendEvent(new OutputEvent(msg, type));
this.setupLogger(true, this.args);
} else {
this.sendEvent(new OutputEvent(msg, type));
}
this.sendEvent(new OutputEvent(msg, type));
}

protected handleRunning(info: MINode) {
Expand Down

0 comments on commit b74c8b1

Please sign in to comment.