-
Notifications
You must be signed in to change notification settings - Fork 105
Adds ILoggingBuilder extension for LanguageServer logging. #187
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
using OmniSharp.Extensions.LanguageServer.Server.Pipelines; | ||
using ISerializer = OmniSharp.Extensions.LanguageServer.Protocol.Serialization.ISerializer; | ||
using System.Reactive.Disposables; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace OmniSharp.Extensions.LanguageServer.Server | ||
{ | ||
|
@@ -106,8 +107,7 @@ public static ILanguageServer PreInit(LanguageServerOptions options) | |
options.TextDocumentIdentifierTypes, | ||
options.InitializeDelegates, | ||
options.InitializedDelegates, | ||
options.LoggingBuilderAction, | ||
options.AddDefaultLoggingProvider | ||
options.LoggingBuilderAction | ||
); | ||
} | ||
|
||
|
@@ -127,20 +127,11 @@ internal LanguageServer( | |
IEnumerable<Type> textDocumentIdentifierTypes, | ||
IEnumerable<InitializeDelegate> initializeDelegates, | ||
IEnumerable<InitializedDelegate> initializedDelegates, | ||
Action<ILoggingBuilder> loggingBuilderAction, | ||
bool addDefaultLoggingProvider) | ||
Action<ILoggingBuilder> loggingBuilderAction) | ||
{ | ||
var outputHandler = new OutputHandler(output, serializer); | ||
|
||
services.AddLogging(builder => | ||
{ | ||
loggingBuilderAction(builder); | ||
|
||
if (addDefaultLoggingProvider) | ||
{ | ||
builder.AddProvider(new LanguageServerLoggerProvider(this)); | ||
} | ||
}); | ||
services.AddLogging(builder => loggingBuilderAction(builder)); | ||
|
||
_reciever = reciever; | ||
_serializer = serializer; | ||
|
@@ -248,11 +239,6 @@ internal LanguageServer( | |
public InitializeParams ClientSettings { get; private set; } | ||
public InitializeResult ServerSettings { get; private set; } | ||
|
||
/// <summary> | ||
/// The minimum level for the server's default logger. | ||
/// </summary> | ||
public LogLevel MinimumLogLevel { get; set; } | ||
|
||
public IServiceProvider Services => _serviceProvider; | ||
|
||
public IDisposable AddHandler(string method, IJsonRpcHandler handler) | ||
|
@@ -357,9 +343,14 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult> | |
{ | ||
ClientSettings = request; | ||
|
||
if (request.Trace == InitializeTrace.Verbose && MinimumLogLevel >= LogLevel.Information) | ||
if (request.Trace == InitializeTrace.Verbose) | ||
{ | ||
MinimumLogLevel = LogLevel.Trace; | ||
var loggerSettings = _serviceProvider.GetService<LanguageServerLoggerSettings>(); | ||
|
||
if (loggerSettings?.MinimumLogLevel >= LogLevel.Information) | ||
{ | ||
loggerSettings.MinimumLogLevel = LogLevel.Trace; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Best would be if we'd also here could notify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably look at a configuration integration. My thought is something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a better way - I had to do something similar for KubeClient: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I solved it by registering an own |
||
} | ||
|
||
_clientVersion = request.Capabilities?.GetClientVersion() ?? ClientVersion.Lsp2; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace OmniSharp.Extensions.LanguageServer.Server | ||
{ | ||
public static class LanguageServerLoggerExtensions | ||
{ | ||
public static ILoggingBuilder AddLanguageServer(this ILoggingBuilder builder, LogLevel minLevel = LogLevel.Information) | ||
{ | ||
builder.Services.AddSingleton<LanguageServerLoggerSettings>(_ => new LanguageServerLoggerSettings { MinimumLogLevel = minLevel }); | ||
builder.Services.AddSingleton<ILoggerProvider, LanguageServerLoggerProvider>(); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace OmniSharp.Extensions.LanguageServer.Server | ||
{ | ||
internal class LanguageServerLoggerSettings | ||
{ | ||
public LogLevel MinimumLogLevel { get; set; } | ||
} | ||
} |
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'd like to avoid having this, but truth is that MEL adds a default filter which works on the factory level, so we won't get our logs to LSP logger if they are < Information (which is default),
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.
As long as it's configured by the consumer (read: Host process) I think that's fine.