pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

Add a colorizeObjects option to disable object colorization #403

Closed Avaq closed 1 year ago

Avaq commented 1 year ago

This allows log parsers that can detect JSON at the end of a log line to do so without being thrown off by ANSI colors.

Specifically, we're using Pino + Pino Pretty with Papertrail. Papertrail has this feature where they parse JSON at the end of a line. But their JSON parser fails to do so when that JSON is surrounded by ANSI codes.

I could disable colorization altogether, but Papertrail does nicely present ANSI colored logs in their web-UI, so I don't want to do that.

I've sent the Papertrail devs a message, because I think it'd be nicest if it were solved on their side, but as a plan B, and for the time being, this is the next best solution.

jsumners commented 1 year ago

I'm confused. Why are you sending the output of pino-pretty to a log collector?

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 4262969590


Totals Coverage Status
Change from base Build 4204181376: 0.0%
Covered Lines: 409
Relevant Lines: 409

💛 - Coveralls
Avaq commented 1 year ago

@jsumners I wish Papertrail would work just as well on JSON logs as it does on formatted logs. But it works much better with formatted logs. As I mentioned, it displays colorized logs output in a web UI. It doesn't have any way to present JSON logs nicely, so you have to send it formatted log output for it to be usable. :confused:

I found the { singleLine: true, colorizeObjects: false }-setup to be the perfect middle ground where we're utilizing all of Papertrail's features maximally.

Avaq commented 1 year ago

We don't need to merge this. I can just use the fork for now and see what comes out of the Papertrail support ticket. Also, I understand that this change doesn't really align with the JSON logger philosophy: Disabling the colors on objects is really just muddying the separation of data and presentation (we're using some part of the presentation as data).

Avaq commented 1 year ago

For reference, here's what the 3 situations look like in Papertrail:

And when sending it unformatted JSON logs, it'll just show the whole JSON object printed as shown in the screenshots, without any way for the user to control how it's formatted.

I don't know if this issue is worth solving here. I just opened the PR because I had the code ready, and it might be useful to some folks.

mcollina commented 1 year ago

(Note that you shouldn't really do what you are doing for the optimal production setup)

mcollina commented 1 year ago

@jsumners PTAL

Avaq commented 1 year ago

@jsumners I pushed a version with updated docs. Sorry I missed this earlier.

Avaq commented 1 year ago

I also heard back from Papertrail. They say it'll take a lot to fix on their end, and they proposed that a change to pino-pretty might be the easiest.

jsumners commented 1 year ago

I also heard back from Papertrail. They say it'll take a lot to fix on their end, and they proposed that a change to pino-pretty might be the easiest.

Of course they will put the onus on the open source community. They have zero incentive to improve their product.