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

Fix OmniSharp log filtering #1293

Merged
merged 3 commits into from Sep 12, 2018
Merged

Conversation

DustinCampbell
Copy link
Contributor

When the logging packages were updated from 1.1 to 2.1, we took a breaking change (aspnet/Announcements#238) that caused the --loglevel switch to no longer work properly. So, passing --loglevel debug doesn't do anything.

This change uses the new APIs for configuring logging and centralizes the filter. Note that I didn't change the LSP implementation because it looks to me like LSP is using loggers differently.

When the logging packages were updated from 1.1 to 2.1, we took a breaking change
(aspnet/Announcements#238) that caused the --loglevel switch to no longer work properly. This
change uses the new APIs for configuring logging and centralizes the filter. Note that I didn't change the LSP implementation
because it looks to me like LSP is using loggers differently.
@@ -33,5 +34,30 @@ public void Dispose()
{
throw new NotImplementedException();
}

private static bool LogFilter(string category, LogLevel level, IOmniSharpEnvironment environment)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this here because LSP is the only one using this method now. It might be that this is unneded, but LSP's logging looked a bit fancier, so I left it.

Copy link
Member

Choose a reason for hiding this comment

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

That should be fine, I'll see if I can take a look at lsp logging later.

var projectEventForwarder = typeof(ProjectEventForwarder).FullName;

builder.AddFilter(
(category, logLevel) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that all of the logic below is inverted from the original HostHelpers.LogFilter(...) method.

@@ -130,7 +135,20 @@ public static IServiceProvider CreateDefaultServiceProvider(IOmniSharpEnvironmen
services.Configure<OmniSharpOptions>(configuration);
services.AddSingleton(configuration);

services.AddLogging();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code below is how logging is supposed to be configured these days. Filtering is a first-class feature for the logging APIs now.

@rchande
Copy link

rchande commented Sep 11, 2018

@DustinCampbell How hard would it be to add some tests for this?

@DustinCampbell
Copy link
Contributor Author

DustinCampbell commented Sep 11, 2018

It'd take a bunch more refactoring. The problem is that we use a different IServiceProvider for tests and that's the component where logging is configured. Let me take a look.

@DustinCampbell
Copy link
Contributor Author

I think I see a place where I can add a test. I'll give it a shot.

@DustinCampbell
Copy link
Contributor Author

DustinCampbell commented Sep 11, 2018

Added a couple of tests. I overestimated the amount of refactoring required. 😄

@@ -33,5 +34,30 @@ public void Dispose()
{
throw new NotImplementedException();
}

private static bool LogFilter(string category, LogLevel level, IOmniSharpEnvironment environment)
Copy link
Member

Choose a reason for hiding this comment

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

That should be fine, I'll see if I can take a look at lsp logging later.

Copy link
Member

@filipw filipw left a comment

Choose a reason for hiding this comment

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

oops thanks for fixing it

@filipw filipw merged commit 4f01058 into OmniSharp:master Sep 12, 2018
@DustinCampbell DustinCampbell deleted the fix-logging branch September 12, 2018 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants