Skip to content

Commit

Permalink
Merge pull request #1963 from OmniSharp/feature/endpoint-error
Browse files Browse the repository at this point in the history
always log error responses with error level
  • Loading branch information
JoeRobich authored Sep 29, 2020
2 parents 7e062c6 + b321dd2 commit db94860
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/OmniSharp.Stdio/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ private async Task HandleRequest(string json, ILogger logger)
}
finally
{
if (logger.IsEnabled(LogLevel.Debug))
// response gets logged when Debug or more detailed log level is enabled
// or when we have unsuccessful response (exception)
if (logger.IsEnabled(LogLevel.Debug) || !response.Success)
{
LogResponse(response.ToString(), logger);
LogResponse(response.ToString(), logger, response.Success);
}

// actually write it
Expand All @@ -257,14 +259,22 @@ void LogRequest(string json, ILogger logger)
}
}

void LogResponse(string json, ILogger logger)
void LogResponse(string json, ILogger logger, bool isSuccess)
{
var builder = _cachedStringBuilder.Acquire();
try
{
builder.AppendLine("************ Response ************ ");
builder.Append(JToken.Parse(json).ToString(Formatting.Indented));
logger.LogDebug(builder.ToString());

if (isSuccess)
{
logger.LogDebug(builder.ToString());
}
else
{
logger.LogError(builder.ToString());
}
}
finally
{
Expand Down

0 comments on commit db94860

Please sign in to comment.