pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.25k stars 147 forks source link

Colorize (syntax highlight) JSON output #229

Open zdila opened 3 years ago

zdila commented 3 years ago

Currently JSON is printed with single color. It would be nice to add syntax highlighting which would make it easier to read especially in the single-line mode.

mcollina commented 3 years ago

Do you know if there is a module that could do that on the terminal?

zdila commented 3 years ago

Quickly googled for example https://www.npmjs.com/package/json-colorizer

mcollina commented 3 years ago

I would prefer an example that does not depend on Chalk, but overall it's a good feature to have.

kibertoad commented 3 years ago

@mcollina Opened https://github.com/joeattardi/json-colorizer/issues/24, let's see what their stance is.

kibertoad commented 3 years ago

@mcollina In case there is no timely response, how would you feel about a PR embedding the json-colorizer functionality inside pino-pretty? It is a fairly small amount of code.

mcollina commented 3 years ago

no prob

kibertoad commented 3 years ago

@mcollina Any recommendations on where in existing codebase to plug in JSON colourizing?

mcollina commented 3 years ago

Not really, I would put it in a separate file for the ease of testing.

kibertoad commented 3 years ago

@mcollina Oh yes, that I would, I was more curious about where to invoke it from within existing code.

mcollina commented 3 years ago

https://github.com/pinojs/pino-pretty/blob/e5e3f5473d76844615e17d67a1e9b55bb20d6385/lib/utils.js#L346 seems a good function to start with.

capaj commented 2 years ago

FYI I've forked the repo to use colorette, so we could potentially use my fork here: https://www.npmjs.com/package/@capaj/json-colorizer

mcollina commented 2 years ago

If we need to fork I prefer it to live in the pino org: anyway, good work!

Could you start integrating that here?

capaj commented 2 years ago

not sure if I have access there, but I can fork my fork there if I do.

capaj commented 2 years ago

no I don't have access there. If you invite me, I can fork and publish it on npm under @pino/json-colorizer

mcollina commented 2 years ago

You should be able to transfer the repo to this org. I'll handle the publish later.

capaj commented 2 years ago

when I try to transfer I get image

kibertoad commented 2 years ago

One has to be a member of the org to transfer repos to the org.

mcollina commented 2 years ago

Here it is: https://www.npmjs.com/package/@pinojs/json-colorizer.

Could you send a PR to integrate it? Thanks!

akindo commented 2 years ago

What's the status on this one? :) Could really use this. 🥇