-
Notifications
You must be signed in to change notification settings - Fork 34.9k
Expose log level and log path to extensions #40142
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
Conversation
src/vs/vscode.d.ts
Outdated
} | ||
|
||
export interface ILogger { | ||
onDidChangeLogLevel: Event<LogLevel>; |
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.
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.
Actually depends... When this is in the env
it should be surely global when it stays in the extension context maybe not... Needs thinking
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.
@mjbvz are imagining different log levels for different things. I think there's a good argument for being able to enable tracing for just one extension. So I think the logLevel and change event should be on the extension's own logger.
src/vs/vscode.d.ts
Outdated
export interface ILogger { | ||
onDidChangeLogLevel: Event<LogLevel>; | ||
getLevel(): LogLevel; | ||
getLogDirectory(): Thenable<string>; |
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.
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.
also, no getter, just a property
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.
It's async because it only creates the directory when requested. It could be a prop of a promise though.
src/vs/vscode.d.ts
Outdated
Off = 7 | ||
} | ||
|
||
export interface ILogger { |
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.
No I
src/vs/vscode.d.ts
Outdated
@@ -4325,6 +4330,29 @@ declare module 'vscode' { | |||
resolveTask(task: Task, token?: CancellationToken): ProviderResult<Task>; | |||
} | |||
|
|||
export enum LogLevel { |
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.
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.
I know this matches the enum we defined in VS Code, but I think we should make Off = 0
. That way, if a js user writes:
if (logger.level) {
...
}
We do the more correct thing
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.
I dunno, the user doesn't need to do that, and that will put the levels out of order. And translating between the enums will be weird.
} | ||
|
||
trace(message: string, ...args: any[]): void { | ||
return this._logService.trace(message, ...args); |
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.
extends ILogService
?
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.
ExtHostLogger extends ILogService? Maybe? It's not used that way
src/vs/vscode.d.ts
Outdated
|
||
export interface ILogger { | ||
onDidChangeLogLevel: Event<LogLevel>; | ||
getLevel(): LogLevel; |
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.
no getter, just a property
constructor( | ||
private readonly _extHostLogService: ExtHostLogService, | ||
private readonly _logService: ILogService, | ||
private readonly _logDirectory: string |
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.
Not really sure I understand but it seems like one logger-instance for all extensions but a different log directory for each. Is that correct and iff so is that desired. Should each extension get its own log file? Should each log message be prefixed with the extension ID otherwise?
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.
I think extension authors would be annoyed at having to read logs with messages from other extensions mixed in. Some extensions will be spammy.
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.
Oh and to explain more, one ExtHostLogger per extension. Each has its own ILogService. ExtHostLogService creates the loggers.
private _loggers: Map<string, ExtHostLogger> = new Map(); | ||
|
||
private _onDidChangeLogLevel: Emitter<LogLevel>; | ||
get onDidChangeLogLevel(): Event<LogLevel> { return this._onDidChangeLogLevel.event; } |
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.
readonly
saves a getter
@roblourens What's the reason for skipping the 'proposed'-api stage? |
I'll make it proposed, and jsdoc is a todo. I wanted feedback on the API before figuring out how to explain it. |
this._extHostLogService.onDidChangeLogLevel(logLevel => this._currentLevel = logLevel); | ||
} | ||
|
||
getLogDirectory(): TPromise<string> { |
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.
memoize this
src/vs/vscode.d.ts
Outdated
@@ -4325,6 +4330,29 @@ declare module 'vscode' { | |||
resolveTask(task: Task, token?: CancellationToken): ProviderResult<Task>; | |||
} | |||
|
|||
export enum LogLevel { |
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.
I know this matches the enum we defined in VS Code, but I think we should make Off = 0
. That way, if a js user writes:
if (logger.level) {
...
}
We do the more correct thing
} | ||
|
||
export class ExtHostLogger implements vscode.ILogger { | ||
private _currentLevel: LogLevel; |
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.
Init this
What's the status of this - I can't find any open cases relating to it. Are you after feedback on the proposed API? Is it likely to ship anytime soon? I'm trying to improve my handling of logs for CI test runs (currently it's hard for me to get at communication with the debugger, etc., from a failed test run) so I'm wondering whether to hold off for this as it might simplify things, or just do it my own way. |
You can follow #43275, we need to move it forward some more next month. I think your scenario would require a way to change the log level from the extension which probably isn't something we'd add. Also, it won't help you log from a debug adapter. They run in their own process and need to handle their own logging. |
Thanks, didn't find that one because I was searching for "logger". I'm actually running debug adapters in-process now to give us more control over launching them, but still a fair point, I'm trying to keep them such that they can run as separate process to. I'll see if I can find a simple way to do what I need for now (I have some intermittent debugger tests I really want to fix) and revisit once this is stable to see if it'll help. Thanks! |
Check out LoggingDebugSession: https://github.com/Microsoft/vscode-debugadapter-node/blob/master/adapter/src/loggingDebugSession.ts and the logger provided by the debug adapter implementation if you haven't seen that yet. |
@roblourens Neat, I hadn't seen that! Though mostly I'm interesting in the communication between my debug adapter and debugger rather than between Code and the DA (however, when setting up my tests, I did struggle with this and ended up hacking a local copy - doh!). |
You can still import and setup the |
Ah, gotcha! Ta! 👍 |
Exposes a logger and also just the log directory for extensions that need to write directly to a file. LogLevel changing stuff is non functional.
Fixes #40053