-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Promote extension log API to stable #43276
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4091,6 +4091,63 @@ declare module 'vscode' { | |
* [`globalState`](#ExtensionContext.globalState) to store key value data. | ||
*/ | ||
storagePath: string | undefined; | ||
|
||
/** | ||
* This extension's logger | ||
*/ | ||
logger: Logger; | ||
} | ||
|
||
/** | ||
* The severity level of a log message | ||
*/ | ||
export enum LogLevel { | ||
Trace = 1, | ||
Debug = 2, | ||
Info = 3, | ||
Warning = 4, | ||
Error = 5, | ||
Critical = 6, | ||
Off = 7 | ||
} | ||
|
||
/** | ||
* A logger for writing to an extension's log file, and accessing its dedicated log directory. | ||
*/ | ||
export interface Logger { | ||
readonly onDidChangeLogLevel: Event<LogLevel>; | ||
readonly currentLevel: LogLevel; | ||
readonly logDirectory: Thenable<string>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically, we make read API synchronous. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The directory is only created when this is called or when the logger is used. Otherwise there will be a ton of empty folders sitting around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roblourens IMHO that is super weird. I've never seen a lazy getter field that creates a directory when accessed. Is there no other way to solve the problem of the empty folders ? Why does each extension need to get its own folder ? Can't we use the extension id as the filename and thus avoid collisions ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If an extension owns it own log file(s), where would it write to? The main logging directory? Then it would have to know about the window id or rotate files itself. It could be a get() method too. |
||
|
||
/** | ||
* Log a message with level `Trace` | ||
*/ | ||
trace(message: string, ...args: any[]): void; | ||
|
||
/** | ||
* Log a message with level `Debug` | ||
*/ | ||
debug(message: string, ...args: any[]): void; | ||
|
||
/** | ||
* Log a message with level `Info` | ||
*/ | ||
info(message: string, ...args: any[]): void; | ||
|
||
/** | ||
* Log a message with level `Warn` | ||
*/ | ||
warn(message: string, ...args: any[]): void; | ||
|
||
/** | ||
* Log a message with level `Error` | ||
*/ | ||
error(message: string | Error, ...args: any[]): void; | ||
|
||
/** | ||
* Log a message with level `Critical` | ||
*/ | ||
critical(message: string | Error, ...args: any[]): void; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the log level be exposed as API ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One use case might be when for when an extension is managing its own logging and writing to a file on its own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has anyone asked for this? There are very many things we could add to the API, but IMHO it is a good practice to be as limited as possible and add something only if really needed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we expose the log directory, we have to expose this, it makes no sense to only provide one.