Skip to content

Commit

Permalink
Merge pull request #1040 from OmniSharp/pretty-json-print
Browse files Browse the repository at this point in the history
pretty print JSON when logging requests/responses in STDIO server
  • Loading branch information
david-driscoll authored Dec 4, 2017
2 parents c10d140 + eb804d6 commit 099a2c1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/OmniSharp.Stdio/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OmniSharp.Endpoint;
using OmniSharp.Mef;
using OmniSharp.Models.UpdateBuffer;
Expand Down Expand Up @@ -160,6 +161,11 @@ public void Start()
}
catch (Exception e)
{
if (e is AggregateException aggregateEx)
{
e = aggregateEx.Flatten().InnerException;
}
_writer.WriteLine(new EventPacket()
{
Event = "error",
Expand Down Expand Up @@ -218,6 +224,11 @@ private async Task HandleRequest(string json, ILogger logger)
}
catch (Exception e)
{
if (e is AggregateException aggregateEx)
{
e = aggregateEx.Flatten().InnerException;
}

// updating the response object here so that the ResponseStream
// prints the latest state when being closed
response.Success = false;
Expand All @@ -241,7 +252,7 @@ void LogRequest(string json, ILogger logger)
try
{
builder.AppendLine("************ Request ************");
builder.Append(json);
builder.Append(JToken.Parse(json).ToString(Formatting.Indented));
logger.LogDebug(builder.ToString());
}
finally
Expand All @@ -256,7 +267,7 @@ void LogResponse(string json, ILogger logger)
try
{
builder.AppendLine("************ Response ************ ");
builder.Append(json);
builder.Append(JToken.Parse(json).ToString(Formatting.Indented));
logger.LogDebug(builder.ToString());
}
finally
Expand Down

0 comments on commit 099a2c1

Please sign in to comment.