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

log request when response fails #2064

Merged
merged 2 commits into from
Jan 15, 2021
Merged
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
13 changes: 10 additions & 3 deletions src/OmniSharp.Stdio/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private async Task HandleRequest(string json, ILogger logger)
var request = RequestPacket.Parse(json);
if (logger.IsEnabled(LogLevel.Debug))
{
LogRequest(json, logger);
LogRequest(json, logger, LogLevel.Debug);
}

var response = request.Reply();
Expand Down Expand Up @@ -236,6 +236,13 @@ private async Task HandleRequest(string json, ILogger logger)
// or when we have unsuccessful response (exception)
if (logger.IsEnabled(LogLevel.Debug) || !response.Success)
{
// if logging is at Debug level, request would have already been logged
// however not for higher log levels, so we want to explicitly log the request too
if (!logger.IsEnabled(LogLevel.Debug))
{
LogRequest(json, logger, LogLevel.Warning);
}

LogResponse(response.ToString(), logger, response.Success);
}

Expand All @@ -244,14 +251,14 @@ private async Task HandleRequest(string json, ILogger logger)
}
}

void LogRequest(string json, ILogger logger)
void LogRequest(string json, ILogger logger, LogLevel logLevel)
{
var builder = _cachedStringBuilder.Acquire();
try
{
builder.AppendLine("************ Request ************");
builder.Append(JToken.Parse(json).ToString(Formatting.Indented));
logger.LogDebug(builder.ToString());
logger.Log(logLevel, builder.ToString());
}
finally
{
Expand Down