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

Promote extension log API to stable #43276

Closed
wants to merge 2 commits into from
Closed

Conversation

roblourens
Copy link
Member

What's the protocol for this? Discussion here and merge it if I get 👍s?

Earlier discussion at 98c58df

Fixes #43275

@roblourens roblourens added the api label Feb 9, 2018
@roblourens roblourens added this to the February 2018 milestone Feb 9, 2018
@roblourens roblourens self-assigned this Feb 9, 2018
Copy link

@nzec nzec left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@nzec
Copy link

nzec commented Feb 9, 2018

Check Travis though. Seems like all good there.

@weinand
Copy link
Contributor

weinand commented Feb 9, 2018

@roblourens I'm fine with the new API but Joh has the final say as he is the API police ;-)

Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

New interfaces look good to me. We should add comments on the Logger interface properties too before shipping this

Copy link
Member

@alexdima alexdima left a comment

Choose a reason for hiding this comment

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

With this addition, we will have two somewhat competing APIs, the output channel and the logger.

IMHO, we should make it clear which one an extension author is supposed to use.

export interface Logger {
readonly onDidChangeLogLevel: Event<LogLevel>;
readonly currentLevel: LogLevel;
readonly logDirectory: 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.

Typically, we make read API synchronous. Why is logDirectory a Thenable ?

Copy link
Member Author

@roblourens roblourens Feb 15, 2018

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 ?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

*/
export interface Logger {
readonly onDidChangeLogLevel: Event<LogLevel>;
readonly currentLevel: LogLevel;
Copy link
Member

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 ?

Copy link
Member Author

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.

Copy link
Member

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...

Copy link
Member Author

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.

@alexdima
Copy link
Member

alexdima commented Feb 16, 2018

@roblourens There is still my question:

As an extension author when should I use an output channel and when should I use the logger?

  • Are we deprecating the output channel API ?
  • The output channel API allows to reveal the output, for example; How can one reveal the extension log via API ?
  • Is it possible to evolve the output channel API rather than deprecate it and replace it with something else ? i.e.:
    • can we add the .trace, .debug, .log etc methods on the output channel
    • can we implement the output channel to use spdlog? (I believe @sandy081 has done some work in this direction)

@roblourens
Copy link
Member Author

I see these as different things, output channel for transient info that users would want to monitor, and logging for bug reports and info for developers.

I'm actually not sure why we show all the log files in the output pane - do we expect users to want to look at these? Even as a developer I don't see generally useful info there unless I'm looking at a specific component or issue.

But if my view is wrong then maybe there's room to merge them instead.

@sandy081
Copy link
Member

Yes, we use spdlog internally for implementing output channels.

We already use Output channel to show extension logs, example: Typescript log. May be there are more extensions doing the same. So, I see the point that it might confuse the authors when to use Output channel and when to use log api. To me, log api looks more as a utility than an API to the extensions.

Also, we can enhance Output to stream the log files from extensions into output channel.

@roblourens
Copy link
Member Author

TypeScript has a verbose logging mode which writes tons of info to a file, but doesn't use the output channel. Spamming the output channel in that case would just slow things down.

I assume that the output channel API transfers all data to the renderer process whether or not the output channel is visible. So that's a big difference between the two.

@sandy081
Copy link
Member

I do not think there will be any slow down or data transfer. If we provide an api to create a file based output channel and if extension has a log file and wanted to show in output channel, then it can create an output channel using the new API passing the log file URI.

Streaming of data happens in the renderer which will be similar to our internal log channels inside product. I did several improvements to output channels in last milestone and one of those is that no streaming happens when a file based channel is not visible.

@alexdima
Copy link
Member

alexdima commented Feb 21, 2018

I see these as different things, output channel for transient info that users would want to monitor, and logging for bug reports and info for developers.

I, personally, as a user, never ever want to see output channels, unless we're talking about the output of executing my program or the output from testing my program. I find it hard to imagine there are people that want to monitor output channels. Take, for example, the following output channels: git, tslint or TypeScript. I could care less what they are writing in the output channel. Also, all the messages in there are crafted by the developers of those components and I have no clue what they mean. The only time I would care is if I would file an issue and the developer asks me to paste that information.

My point is that nobody wants to monitor output channels as part of their regular flow, similar to how nobody wants to monitor log files as part of their regular flow. So, IMHO, output channels are log files. They simply miss some tracing level, some special methods to avoid writing ifs all over the place, and perhaps could benefit from more optimization. I am not sure if the output is written to disk directly from the extension host process or it travels to the renderer process; we could write it to disk from the extension host process for all output channels, as they would all benefit from this optimization.

If I understand you correctly, we have the requirement that extensions maybe want to log from a separate process than the extension host. In such a case, I believe they would use a logging library available in their runtime's programming language. e.g. OmniSharp would use a logger written in C#, TypeScript could also use spdlog, etc. I understand how it is useful in such a case for them to write their log files close to the other VS Code log files, and us giving them a folder path and log level API makes good sense. It's just that these should be synchronous, not asynchronous, and should be pure. Getting a property should, IMHO, have no side effects, such as creating a folder on disk...

@jrieken
Copy link
Member

jrieken commented Mar 1, 2018

What's the protocol for this?

@roblourens Glad you are asking..

  1. start are the api guidelines, then
  2. propose something that doesn't conflict with the guidelines, then
  3. discuss.

In this PR we are still on phase 2 (propose something that doesn't conflict with the guidelines) and maybe on something like phase 0 - in what shape do we want/need this api.

I agree with @alexandrudima that there is too much overlap with output channels (be minimal) and if we untangle the proposal into two pieces we might end up with a better solution. One part of this proposal is being part of the vs code logging infrastructure and using (improved) output channels seems like a promising idea/exploration. The other part is exposing log config data, like level and file location. If those aren't extension-specific we should look into adding something to vscode.env, if they are extension specific something on the ExtensionContext is required.

@jrieken jrieken added the log VS Code log issues label Mar 1, 2018
@kieferrm kieferrm mentioned this pull request Mar 13, 2018
70 tasks
@jrieken
Copy link
Member

jrieken commented Mar 15, 2018

Outcome of discussing this

  • have logDirectory a property of the extension context (in the spirit of storagePath)
  • move log level information and corresponding event to vscode.env as there is only a global log level in vscode
  • move the logging-related methods to the output channel api.

We are aiming to deliver the first two items during this milestone and consider the last as stretch.

@roblourens
Copy link
Member Author

This PR is now n/a

@roblourens roblourens closed this Mar 22, 2018
@kieferrm kieferrm mentioned this pull request Aug 7, 2018
39 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2020
@roblourens roblourens deleted the roblou/promoteExtLogAPI branch June 29, 2020 19:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api log VS Code log issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promote extension log API to stable
7 participants