-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Improve Extensions logging #159892
Comments
Proposal: export enum LogLevel {
Trace = 0,
Debug = 1,
Info = 2,
Warning = 3,
Error = 4,
Critical = 5,
Off = 6,
}
export interface ExtensionContext {
log(level: LogLevel, message: string, ...args: any[]): void;
log(level: LogLevel.Error | LogLevel.Critical, e: Error, ...args: any[]): void;
} Expose VS Code also allows user to control the log level per extension. |
There is no denying that this is useful and helps to streamline extensions but similar ideas have already been discussed and discard in #85992 and #40053 (comment). The reasoning is that the existing So, instead of the proposal I would suggest something like this: export interface OutputChannel {
// all existing
info(message: string): void;
warn(message: string): void;
error(error: string | Error): void;
} |
I do not like combining logger with OutputChannel because of its existing features. For eg., One can append text in the same line and append a line of text as is in the OutputChannel. In contrary, Log API will log the message per line and adds pre-text like I just noticed that the current proposal is actually one of the recommendations in earlier discussions here To be clear, the current proposal does not allow extensions to create loggers, instead it provides a logger per extension to log data. |
Isn't that up to the extension and something that very easy to "fix" Alternatively or in addition you can have a new argument to
Well, clear is view property, not a model change. Just like I can clear a true log output view today. Replace needs some thinking but with the |
I changed the proposal by introducing a export interface Logger {
trace(message: string, ...args: any[]): void;
debug(message: string, ...args: any[]): void;
info(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
error(message: string | Error, ...args: any[]): void;
critical(message: string | Error, ...args: any[]): void;
}
export interface ExtensionContext {
readonly logger: Logger;
} I am still not sure if this |
Here is the new proposal - aligning with Output Channel - after discussing in the API call export interface AbstractOutputChannel {
/**
* The human-readable name of this output channel.
*/
readonly name: string;
/**
* Append the given value and a line feed character
* to the channel.
*
* @param value A string, falsy values will be printed.
*/
appendLine(value: string): void;
/**
* Reveal this channel in the UI.
*
* @param preserveFocus When `true` the channel will not take focus.
*/
show(preserveFocus?: boolean): void;
/**
* Hide this channel from the UI.
*/
hide(): void;
/**
* Dispose and free associated resources.
*/
dispose(): void;
}
/**
* An output channel is a container for readonly textual information.
*
* To get an instance of an `OutputChannel` use
* {@link window.createOutputChannel createOutputChannel}.
*/
export interface OutputChannel extends AbstractOutputChannel {
/**
* Append the given value to the channel.
*
* @param value A string, falsy values will not be printed.
*/
append(value: string): void;
/**
* Replaces all output from the channel with the given value.
*
* @param value A string, falsy values will not be printed.
*/
replace(value: string): void;
/**
* Removes all output from the channel.
*/
clear(): void;
/**
* Reveal this channel in the UI.
*
* @deprecated Use the overload with just one parameter (`show(preserveFocus?: boolean): void`).
*
* @param column This argument is **deprecated** and will be ignored.
* @param preserveFocus When `true` the channel will not take focus.
*/
show(column?: ViewColumn, preserveFocus?: boolean): void;
}
/**
* A channel for containing log output.
*/
export interface LogOutputChannel extends AbstractOutputChannel {
/**
* Log the given trace message to the channel.
*
* Messages are only printed when the user has enabled trace logging for the extension.
*
* @param message trace message to log
*/
trace(message: string): void;
/**
* Log the given debug message to the channel.
*
* Messages are only printed when the user has enabled debug logging for the extension.
*
* @param message debug message to log
*/
debug(message: string): void;
/**
* Log the given info message to the channel.
*
* Messages are only printed when the user has enabled info logging for the extension.
*
* @param message info message to log
*/
info(message: string): void;
/**
* Log the given warning message to the channel.
*
* Messages are only printed when the user has enabled warn logging for the extension.
*
* @param message warning message to log
*/
warn(message: string): void;
/**
* Log the given error or error message to the channel.
*
* Messages are only printed when the user has enabled error logging for the extension.
*
* @param error Error or error message to log
*/
error(error: string | Error): void;
}
export namespace window {
/**
* Creates a new {@link LogOutputChannel log output channel} with the given name.
*
* @param name Human-readable string which will be used to represent the channel in the UI.
* @param options Options for the log output channel.
*/
export function createOutputChannel(name: string, options: { readonly log: true }): LogOutputChannel;
} |
How does this happen? |
This is not yet supported. Updated the doc. |
Updated Proposal export enum LogLevel {
Trace = 0,
Debug = 1,
Info = 2,
Warning = 3,
Error = 4,
Critical = 5,
Off = 6
}
export namespace env {
/**
* The current log level of the application.
*/
export const logLevel: LogLevel;
/**
* An {@link Event} which fires when the log level of the application changes.
*/
export const onDidChangeLogLevel: Event<LogLevel>;
}
/**
* A channel for containing log output.
*/
export interface LogOutputChannel extends OutputChannel {
/**
* The current log level of the channel.
*/
readonly logLevel: LogLevel;
/**
* An {@link Event} which fires when the log level of the channel changes.
*/
readonly onDidChangeLogLevel: Event<LogLevel>;
/**
* Log the given trace message to the channel.
*
* Messages are only printed when the user has enabled trace logging.
*
* @param message trace message to log
*/
trace(message: string, ...args: any[]): void;
/**
* Log the given debug message to the channel.
*
* Messages are only printed when the user has enabled debug logging.
*
* @param message debug message to log
*/
debug(message: string, ...args: any[]): void;
/**
* Log the given info message to the channel.
*
* Messages are only printed when the user has enabled info logging.
*
* @param message info message to log
*/
info(message: string, ...args: any[]): void;
/**
* Log the given warning message to the channel.
*
* Messages are only printed when the user has enabled warn logging.
*
* @param message warning message to log
*/
warn(message: string, ...args: any[]): void;
/**
* Log the given error or error message to the channel.
*
* Messages are only printed when the user has enabled error logging.
*
* @param error Error or error message to log
*/
error(error: string | Error, ...args: any[]): void;
}
export namespace window {
/**
* Creates a new {@link LogOutputChannel log output channel} with the given name.
*
* @param name Human-readable string which will be used to represent the channel in the UI.
* @param options Options for the log output channel.
*/
export function createOutputChannel(name: string, options: { readonly log: true }): LogOutputChannel;
} |
For logging, at present all extensions are doing following:
This is to simplify logging for extensions by providing an API that all extension can use to log in VS Code's log format
For example, This is how GitHub auth extension looks now
If VS Code supports logging for extensions, this will look and behave similar to VS Code logs
Proposal
The text was updated successfully, but these errors were encountered: