Skip to content

Commit

Permalink
Merge pull request #71 from tintoy/feature/server-log-level
Browse files Browse the repository at this point in the history
Implement configurable log level for language server's built-in logger.
  • Loading branch information
david-driscoll authored Feb 12, 2018
2 parents 023ac40 + 6997768 commit 039aa27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ internal LanguageServer(
public InitializeParams Client { get; private set; }
public InitializeResult Server { get; private set; }

/// <summary>
/// The minimum level for the server's default logger.
/// </summary>
public LogLevel MinimumLogLevel { get; set; } = LogLevel.Information;

public IDisposable AddHandler(string method, IJsonRpcHandler handler)
{
var handlerDisposable = _collection.Add(method, handler);
Expand Down
9 changes: 4 additions & 5 deletions src/Server/LanguageServerLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ public IDisposable BeginScope<TState>(TState state)
return new ImmutableDisposable();
}

public bool IsEnabled(LogLevel logLevel)
{
// TODO: setup as configuration somehwhere (from trace perhaps?)
return true;
}
public bool IsEnabled(LogLevel logLevel) => logLevel >= _languageServer.MinimumLogLevel;

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (logLevel < _languageServer.MinimumLogLevel)
return;

if (TryGetMessageType(logLevel, out var messageType))
{
_languageServer.Log(new LogMessageParams()
Expand Down

0 comments on commit 039aa27

Please sign in to comment.