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

pretty print JSON when logging requests/responses in STDIO server #1040

Merged
merged 1 commit into from
Dec 4, 2017

Conversation

filipw
Copy link
Member

@filipw filipw commented Dec 1, 2017

Instead of logging STDIO Server requests/responses like this:

        ************ Request ************
{"Type":"request","Seq":30,"Command":"/findusages","Arguments":{"FileName":"c:\\code\\csharp-scripting-demos\\build\\build.csx","Line":14,"Column":5,"OnlyThisFile":false,"ExcludeDefinition":true}}
[dbug]: OmniSharp.Stdio.Host
        ************  Response ************ 
{"Request_seq":30,"Command":"/findusages","Running":true,"Success":true,"Message":null,"Body":{"QuickFixes":[{"FileName":"c:\\code\\csharp-scripting-demos\\build\\build.csx","Line":41,"Column":25,"EndLine":41,"EndColumn":35,"Text":"if (!Directory.Exists(outputPath)) {","Projects":["build.csx"]},{"FileName":"c:\\code\\csharp-scripting-demos\\build\\build.csx","Line":42,"Column":31,"EndLine":42,"EndColumn":41,"Text":"Directory.CreateDirectory(outputPath);","Projects":["build.csx"]},{"FileName":"c:\\code\\csharp-scripting-demos\\build\\build.csx","Line":47,"Column":39,"EndLine":47,"EndColumn":49,"Text":"p.OutputPath = Path.Combine(\"..\", outputPath);","Projects":["build.csx"]}]},"Seq":185,"Type":"response"}
[dbug]: OmniSharp.Stdio.Host

We now log them like this:

        ************ Request ************
{
  "Type": "request",
  "Seq": 17,
  "Command": "/findusages",
  "Arguments": {
    "FileName": "c:\\code\\csharp-scripting-demos\\build\\build.csx",
    "Line": 14,
    "Column": 5,
    "OnlyThisFile": false,
    "ExcludeDefinition": true
  }
}
[dbug]: OmniSharp.Stdio.Host
        ************  Response ************ 
{
  "Request_seq": 17,
  "Command": "/findusages",
  "Running": true,
  "Success": true,
  "Message": null,
  "Body": {
    "QuickFixes": [
      {
        "FileName": "c:\\code\\csharp-scripting-demos\\build\\build.csx",
        "Line": 41,
        "Column": 25,
        "EndLine": 41,
        "EndColumn": 35,
        "Text": "if (!Directory.Exists(outputPath)) {",
        "Projects": [
          "build.csx"
        ]
      },
      {
        "FileName": "c:\\code\\csharp-scripting-demos\\build\\build.csx",
        "Line": 42,
        "Column": 31,
        "EndLine": 42,
        "EndColumn": 41,
        "Text": "Directory.CreateDirectory(outputPath);",
        "Projects": [
          "build.csx"
        ]
      },
      {
        "FileName": "c:\\code\\csharp-scripting-demos\\build\\build.csx",
        "Line": 47,
        "Column": 39,
        "EndLine": 47,
        "EndColumn": 49,
        "Text": "p.OutputPath = Path.Combine(\"..\", outputPath);",
        "Projects": [
          "build.csx"
        ]
      }
    ]
  },
  "Seq": 142,
  "Type": "response"
}

This very much helps the readability of the log output. Additionally, flattened AggregateException.
Note that I didn't change formatting here https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.Abstractions/Stdio/Protocol/Packet.cs#L22 as there is no reason to increase the payload size on the protocol - it's just when we log.

Copy link
Contributor

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

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

:shipit:

@david-driscoll david-driscoll merged commit 099a2c1 into master Dec 4, 2017
@filipw filipw deleted the pretty-json-print branch October 16, 2018 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants