BSiLabs / HttpTracer

MIT License
172 stars 13 forks source link

[Enhancement] JSON Response appearing indented as JSON #44

Closed saamerm closed 3 years ago

saamerm commented 4 years ago

Sup guys! I am not sure if this is already possible, but I am not able to figure out if using the package I can make my JSON response appear as indented JSON, so that it's easier to read. Currently I have to

  1. Copy the response I get:

    image
  2. Paste it into VS Code,

  3. Remove the Debug stuff in the beginning of the lines that come after the first line

  4. Remove the line breaks and put all of the response in one line

  5. Then paste it into https://jsonformatter.curiousconcept.com/ and click "Process"

Which is a lot of steps, so it would be awesome if there was a way to just change the config so HttpTracer does that!

ChaseFlorell commented 4 years ago

you should be able to just copy the http request/response without additional debug info. Does your output not look like this?

INFO:  ==================== HTTP REQUEST: [POST] ==================== 
POST https://xxx.azurewebsites.net/api/entityChangesList
Authorization: Bearer aeiod
client-version: 1.0.0

{"some","value"}

INFO:  ==================== HTTP RESPONSE: [SUCCEEDED: 200 OK] ==================== 

POST https://xxx.azurewebsites.net/api/entityChangesList
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Vary: Accept-Encoding
Server: Microsoft-IIS/10.0
Request-Context: appId=cid-v1:f8caa0cc-5524-4232-86b3-8aad02b0ae0b
Access-Control-Expose-Headers: Request-Context
X-Powered-By: ASP.NET
Date: Sun, 01 Mar 2020 16:53:03 GMT
Content-Length: 122
Content-Type: application/json; charset=utf-8
}

["some","response"]
saamerm commented 4 years ago

Hey thanks for the quick reply!

It appears like this

image

But I was wondering if i can make it look like this:

image

(Obviously uncollapsed, collapsing was just done to hide the data)

ChaseFlorell commented 4 years ago

So, we purposely print it on a single line, but your output still doesn't look quite right. What is your log level?

using HttpTracer;
public async Task GetMyData()
{
    var tracer = new HttpTracerHandler();
    tracer.Verbosity = LogLevel.Information; // this line here
    var client = new HttpClient(tracer);
    var result = await client.GetAsync("http://myserviceurl.com");
}
saamerm commented 4 years ago

It's just set to Default using this line tracer.Verbosity = HttpTracerHandler.DefaultVerbosity;

It's separate, but I wasn't able to get access to LogLevel, do I use Splat?

ChaseFlorell commented 4 years ago

you don't need splat. Try updating your "MessageParts" to All and see if it yields better results.

https://github.com/BSiLabs/HttpTracer/blob/e9af456e1f615103c6eab5696eee2d48b07e37aa/src/HttpTracer.Tests/HttpTracerTests.cs#L69

saamerm commented 4 years ago

Hmm.. I tried that. I'm talking about something shown here, like: Console.WriteLine(JsonConvert.SerializeObject(jsonString, Formatting.Indented));

ChaseFlorell commented 4 years ago

That would be a good feature for sure. Probably want to stick it behind an enum configuration value.

Happy to take a pull request đŸ˜‰

saamerm commented 4 years ago

Sure! Any quick tips to what files I would be changing?

ChaseFlorell commented 4 years ago

Take a look at the MessageParts and do the same. Values should be something like.

None = 1<<0, //default IndentRequest = 1<<1, IndentResponse = 1<<2, IndentAll = IndentRequest|IndentResponse

Enum name could be something like OutputFormatting

But, feel free to think of something better. NamingIsHardâ„¢

ChaseFlorell commented 3 years ago

@saamerm I am trying to get this feature through as a part of #51