Skip to content

Commit

Permalink
Log debug adapter traffic (#7219)
Browse files Browse the repository at this point in the history
Add a "verbose" logging level
Fix #6468
  • Loading branch information
roblourens authored and joyceerhl committed Aug 23, 2021
1 parent 59cb950 commit 607e524
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,8 @@
"error",
"warn",
"info",
"debug"
"debug",
"verbose"
],
"description": "The logging level the extension logs at.",
"scope": "machine"
Expand Down
3 changes: 3 additions & 0 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ function convertSettingTypeToLogLevel(setting: LoggingLevelSettingType | undefin
case 'debug': {
return LogLevel.Debug;
}
case 'verbose': {
return LogLevel.Trace;
}
default: {
return LogLevel.Error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export interface IWatchableJupyterSettings extends IJupyterSettings {
readonly onDidChange: Event<void>;
}

export type LoggingLevelSettingType = 'off' | 'error' | 'warn' | 'info' | 'debug';
export type LoggingLevelSettingType = 'off' | 'error' | 'warn' | 'info' | 'debug' | 'verbose';

export interface ILoggingSettings {
readonly level: LogLevel | 'off';
Expand Down
9 changes: 8 additions & 1 deletion src/client/debugger/jupyter/kernelDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as path from 'path';
import { IJupyterSession } from '../../datascience/types';
import { KernelMessage } from '@jupyterlab/services';
import { ICommandManager } from '../../common/application/types';
import { traceError } from '../../common/logger';
import { traceError, traceVerbose } from '../../common/logger';
import { IFileSystem } from '../../common/platform/types';
import { IKernelDebugAdapter } from '../types';
import { IDisposable } from '../../common/types';
Expand Down Expand Up @@ -202,6 +202,12 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
this,
this.disposables
);

this.disposables.push(this.onDidSendMessage((msg) => this.trace('to client', JSON.stringify(msg))));
}

private trace(tag: string, msg: string) {
traceVerbose(`[Debug] ${tag}: ${msg}`);
}

async handleMessage(message: DebugProtocol.ProtocolMessage) {
Expand Down Expand Up @@ -342,6 +348,7 @@ export class KernelDebugAdapter implements DebugAdapter, IKernelDebugAdapter, ID
}
});

this.trace('to kernel', JSON.stringify(message));
if (message.type === 'request') {
this.sendMessage.fire(message);
const request = debugRequest(message as DebugProtocol.Request, this.jupyterSession.sessionId);
Expand Down
6 changes: 5 additions & 1 deletion src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ async function activateLegacy(
// We should start logging using the log level as soon as possible, so set it as soon as we can access the level.
// `IConfigurationService` may depend any of the registered types, so doing it after all registrations are finished.
// XXX Move this *after* abExperiments is activated?
setLoggingLevel(configuration.getSettings().logging.level);
const settings = configuration.getSettings();
setLoggingLevel(settings.logging.level);
settings.onDidChange(() => {
setLoggingLevel(settings.logging.level);
});

// Register datascience types after experiments have loaded.
// To ensure we can register types based on experiments.
Expand Down
2 changes: 1 addition & 1 deletion src/client/logging/_global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function log(logLevel: LogLevel, ...args: Arguments) {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function logVerbose(...args: any[]) {
log(LogLevel.Info, ...args);
log(LogLevel.Trace, ...args);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 607e524

Please sign in to comment.