Skip to content

Conversation

roblourens
Copy link
Member

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

}

export interface ILogger {
onDidChangeLogLevel: Event<LogLevel>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

Copy link
Member Author

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.

export interface ILogger {
onDidChangeLogLevel: Event<LogLevel>;
getLevel(): LogLevel;
getLogDirectory(): Thenable<string>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

Copy link
Member Author

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.

Off = 7
}

export interface ILogger {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I

@@ -4325,6 +4330,29 @@ declare module 'vscode' {
resolveTask(task: Task, token?: CancellationToken): ProviderResult<Task>;
}

export enum LogLevel {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends ILogService?

Copy link
Member Author

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


export interface ILogger {
onDidChangeLogLevel: Event<LogLevel>;
getLevel(): LogLevel;
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly saves a getter

@jrieken
Copy link
Member

jrieken commented Dec 13, 2017

@roblourens What's the reason for skipping the 'proposed'-api stage?

@roblourens
Copy link
Member Author

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> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memoize this

@@ -4325,6 +4330,29 @@ declare module 'vscode' {
resolveTask(task: Task, token?: CancellationToken): ProviderResult<Task>;
}

export enum LogLevel {
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init this

@roblourens roblourens merged commit 91c8e61 into master Dec 15, 2017
@joaomoreno joaomoreno deleted the roblou/extHostLogger2 branch December 15, 2017 07:13
@DanTup
Copy link
Contributor

DanTup commented Apr 24, 2018

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.

@roblourens
Copy link
Member Author

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.

@DanTup
Copy link
Contributor

DanTup commented Apr 24, 2018

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!

@roblourens
Copy link
Member Author

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.

@DanTup
Copy link
Contributor

DanTup commented Apr 24, 2018

@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!).

@roblourens
Copy link
Member Author

You can still import and setup the logger object from the adapter and use that to write to a file. It will at least do some of the work for you. I use this all over https://github.com/microsoft/vscode-chrome-debug-core to log communication between the debug adapter and Chrome/Node.

@DanTup
Copy link
Contributor

DanTup commented Apr 24, 2018

Ah, gotcha! Ta! 👍

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose log level and log path to extensions
4 participants