Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rawLog option for OutputChannel to colourise the Ark log #1589

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions extensions/jupyter-adapter/src/JupyterKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ export class JupyterKernel extends EventEmitter implements vscode.Disposable {
// Establish a log channel for the kernel we're connecting to, if we
// don't already have one (we will if we're restarting)
if (!this._logChannel) {
this._logChannel = vscode.window.createOutputChannel(`Runtime: ${this._spec.display_name}`);
// @ts-ignore - Hidden API entry
this._logChannel = vscode.window.createRawLogOutputChannel(`Runtime: ${this._spec.display_name}`);
}

// Bind to the Jupyter session
Expand All @@ -322,7 +323,7 @@ export class JupyterKernel extends EventEmitter implements vscode.Disposable {
// file.
const logFilePath = this._session!.state.logFile;
if (fs.existsSync(logFilePath)) {
this.streamLogFileToChannel(logFilePath, this._spec.language, this._logChannel);
this.streamLogFileToChannel(logFilePath, this._spec.language, this._logChannel!);
}

// Connect to the kernel's sockets; wait for all sockets to connect before continuing
Expand Down
9 changes: 9 additions & 0 deletions src/vs/platform/log/node/spdlogLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ export class SpdLogLogger extends AbstractMessageLogger implements ILogger {
}
}

// --- Start Positron ---
// Override pattern to avoid adding timestamps etc
public setRawLogger() {
this._loggerCreationPromise.then(() => {
this._logger!.setPattern('%v');
});
}
// --- End Positron ---

protected log(level: LogLevel, message: string): void {
if (this._logger) {
log(this._logger, level, message);
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,13 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
createOutputChannel(name: string, options: string | { log: true } | undefined): any {
return extHostOutputService.createOutputChannel(name, options, extension);
},
// --- Start Positron ---
// This is a hidden API entry, don't expect it in the public `vscode.window`
// @ts-ignore
createRawLogOutputChannel(name: string): any {
return extHostOutputService.createRawLogOutputChannel(name, extension);
},
// --- End Positron ---
createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn; preserveFocus?: boolean }, options?: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
return extHostWebviewPanels.createWebviewPanel(extension, viewType, title, showOptions, options);
},
Expand Down
34 changes: 34 additions & 0 deletions src/vs/workbench/api/common/extHostOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class ExtHostOutputChannel extends AbstractMessageLogger implements vscode.LogOu
this._register(logger.onDidChangeLogLevel(level => this.setLevel(level)));
}

// --- Start Positron ---
public setRawLogger() {
let loggerUnchecked = this.logger as any;
if (loggerUnchecked.setRawLogger) {
loggerUnchecked.setRawLogger();
};
}
// --- End Positron ---

get logLevel(): LogLevel {
return this.getLevel();
}
Expand Down Expand Up @@ -161,6 +170,24 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
return log ? this.createExtHostLogOutputChannel(name, logLevel ?? this.logService.getLevel(), <Promise<ExtHostOutputChannel>>extHostOutputChannel) : this.createExtHostOutputChannel(name, <Promise<ExtHostOutputChannel>>extHostOutputChannel);
}

// --- Start Positron ---
// Variant of createOutputChannel() that creates a "raw log" output channel.
// Compared to a normal `LogOutputChannel`, this doesn't add timestamps or info
// level. It's meant for extensions that create fully formed log lines but still
// want to benefit from the colourised rendering of log output channels.
createRawLogOutputChannel(name: string, extension: IExtensionDescription): vscode.OutputChannel {
const channel = this.createOutputChannel(name, { log: true }, extension);

// Set our custom raw log
const channelUnchecked = channel as any
if (channelUnchecked.setRawLogger) {
channelUnchecked.setRawLogger();
}

return channel;
}
// --- End Positron ---

private async doCreateOutputChannel(name: string, languageId: string | undefined, extension: IExtensionDescription): Promise<ExtHostOutputChannel> {
if (!this.outputDirectoryPromise) {
this.outputDirectoryPromise = this.extHostFileSystem.value.createDirectory(this.outputsLocation).then(() => this.outputsLocation);
Expand Down Expand Up @@ -216,6 +243,13 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
validate();
channelPromise.then(channel => channel.appendLine(value));
},
// --- Start Positron ---
// @ts-ignore
setRawLogger(): void {
validate();
channelPromise.then(channel => channel.setRawLogger());
},
// --- End Positron ---
clear(): void {
validate();
channelPromise.then(channel => channel.clear());
Expand Down