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 HTTP logging #1456

Merged
merged 2 commits into from
Apr 17, 2019
Merged

Fix HTTP logging #1456

merged 2 commits into from
Apr 17, 2019

Conversation

nickspoons
Copy link
Member

As described in #1446, the HTTP version of OmniSharp-roslyn does not log any output.

I managed to find the commit where the logging stopped working, it was 4f9fb4d by @DustinCampbell. In that commit the HostHelpers.LogFilter() functionality was refactored into CompositionHostBuilder.CreateDefaultServiceProvider(), which has a configureLogging callback argument.

The problem here is that in the HTTP configureLogging callback, ExceptionHandlerMiddleware is included in a filter like this:

var exceptionHandlerMiddlewareName = typeof(ExceptionHandlerMiddleware).FullName;
builder.AddFilter(
    (category, logLevel) => category.Equals(exceptionHandlerMiddlewareName, StringComparison.OrdinalIgnoreCase));

This filter is applied on top of the filter already added in CompositionHostBuilder.CreateDefaultServiceProvider(), which looks like this:

var workspaceInformationServiceName = typeof(WorkspaceInformationService).FullName;
var projectEventForwarder = typeof(ProjectEventForwarder).FullName;

builder.AddFilter(
    (category, logLevel) =>
        environment.LogLevel <= logLevel &&
        category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) &&
        !category.Equals(workspaceInformationServiceName, StringComparison.OrdinalIgnoreCase) &&
        !category.Equals(projectEventForwarder, StringComparison.OrdinalIgnoreCase));

The simplest way I have found to ensure that the HTTP filter doesn't clobber the CompositionHostBuilder filter is to duplicate the entire CompositionHostBuilder filter in the HTTP code:

var workspaceInformationServiceName = typeof(WorkspaceInformationService).FullName;
var projectEventForwarder = typeof(ProjectEventForwarder).FullName;
var exceptionHandlerMiddlewareName = typeof(ExceptionHandlerMiddleware).FullName;

builder.AddFilter(
    (category, logLevel) =>
        category.Equals(exceptionHandlerMiddlewareName, StringComparison.OrdinalIgnoreCase) ||
        (_environment.LogLevel <= logLevel &&
            category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) &&
            !category.Equals(workspaceInformationServiceName, StringComparison.OrdinalIgnoreCase) &&
            !category.Equals(projectEventForwarder, StringComparison.OrdinalIgnoreCase)));

This is not a very clean solution so please let me know if there's a tidier way to do this.

Fixes #1446

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.

Thanks - I tested it locally and indeed it works well. We can take it as-is to resolve the issue 👍

@filipw filipw merged commit 2327cb2 into OmniSharp:master Apr 17, 2019
@nickspoons nickspoons deleted the fix-http-logging branch April 17, 2019 19:31
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.

No output from Http version
2 participants