Skip to content

Allow using global log level as minimum log level for LanguageServerLoggerProvider #189

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sample/SampleServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static async Task MainAsync(string[] args)
.WithOutput(Console.OpenStandardOutput())
.ConfigureLogging(x => x
.AddSerilog()
.AddLanguageServer(LogLevel.Error)
.SetMinimumLevel(LogLevel.Error))
.AddLanguageServer()
.SetMinimumLevel(LogLevel.Information))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe worth changing this to like Debug or Trace since Information is the default? Or is something else the default?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct, Information is the default level.

.WithHandler<TextDocumentHandler>()
.WithHandler<DidChangeWatchedFilesHandler>()
.WithHandler<FoldingRangeHandler>()
Expand Down
15 changes: 14 additions & 1 deletion src/Server/Logging/LanguageServerLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ namespace OmniSharp.Extensions.LanguageServer.Server
{
public static class LanguageServerLoggerExtensions
{
public static ILoggingBuilder AddLanguageServer(this ILoggingBuilder builder, LogLevel minLevel = LogLevel.Information)
public static ILoggingBuilder AddLanguageServer(this ILoggingBuilder builder)
{
builder.Services.AddSingleton<LanguageServerLoggerSettings>(services => {
var filterOptions = services.GetService<IOptions<LoggerFilterOptions>>();

return new LanguageServerLoggerSettings { MinimumLogLevel = filterOptions.Value.MinLevel };
});

builder.Services.AddSingleton<ILoggerProvider, LanguageServerLoggerProvider>();

return builder;
}

public static ILoggingBuilder AddLanguageServer(this ILoggingBuilder builder, LogLevel minLevel)
{
builder.Services.AddSingleton<LanguageServerLoggerSettings>(_ => new LanguageServerLoggerSettings { MinimumLogLevel = minLevel });
builder.Services.AddSingleton<ILoggerProvider, LanguageServerLoggerProvider>();
Expand Down