sirrodgepodge/morgan-body

Disable colors and pretty printing

rserentill opened this issue · 9 comments

Hi, colors look reaaly cool when printed on the console, but when logging to a file, it apperars a bit broken, like that:

[96mRequest: [93mPOST [97m/login

Also, would be great if you could disable pretty printing for when the stream is set to a log file.

Thanks!

Totally true, thank you for this request, just added noColors option, published to NPM, it's in 2.4.0.

In the future will need to add different log themes :D

Oh I just realized I missed your second ask.

What do you mean by disable pretty printing? getting rid of whitespace?

@rserentill Can you give an example of with pretty printing and without?

Great! thanks!

With pretty printing I meanmultiple lines and indentation of a JSON object. For example, this would be pretty printed:

requestBody: {
    user: "blabla",
    password: "blabla"
}

For a log file, it would be great to be able to log everything in one line, like:

requestBody: {user: "blabla", password: "blabla"}

This way is easier to automatically parse the log file for printing charts on whatever.

Again, thanks for the work and hope you find this interesting!

Cheers!

okay got it, it's okay if these are each still on separate lines right? just put the request and response JSONs on the same line like so and that will work for you right (as opposed to all of these being on the same liine)?
Request: GET / at Wed Mar 07 2018 22:08:17 GMT-0500, User Agent: Mozilla/5.0
Request Body: { user: "blabla", password: "blabla" }
Response Body: { user: "blabla", info: { key: "blabla" } }
Response: 200 536.048 ms - 45

I will do it this weekend, I just want to be 100% sure I get it right

Hey, thanks for the answer!

Well, in the case of a log file, the best would be, in my opinion, a line for each event. Because an event is marked with a timestamp and you will have a line for each timestamp. In a log file the important thing is not the appearence, but the standard format, so a third tool party can parse the file and get the right data.

So in this case, I think it should be:
Request: GET / at Wed Mar 07 2018 22:08:17 GMT-0500, User Agent: Mozilla/5.0 Request Body: { user: "blabla", password: "blabla" } Response Body: { user: "blabla", info: { key: "blabla" } } Response: 200 536.048 ms - 45

I know it looks kind of messy, but this is mostly not for a user to read (as it is the console output) but for a program to parse.

hm okay, I think the best I can do is put the request on one line and the response on the other since they happen at different times.

You could put the whole request+response on one line at response time but then you run into issue with the fact that a response is not guaranteed (in fact sometimes your server crashes due to a bug in the logic handling particular request, you cannot log anything once the server crashes but it's very nice to see the log of the request that came in while diagnosing the issue).

could really use no-pretty option too. For both stdout and file_logging.
Use case -> for particular logs you NEED to see the full request log without setting a count limit (like search query for example) and in pretty format -> that's really inconvenient. While I still want to use the rest of functionality provided by the library

this is done thanks to @dvrajan! #14 Apologies on the wait!

Also check out the new themes :)

please confirm that your use cases are covered by the prettify: false and noColors: true options

I will take that heart to mean you're all set then @rserentill :)