uber-go / zap

Blazing fast, structured, leveled logging in Go.
https://pkg.go.dev/go.uber.org/zap
MIT License
21.93k stars 1.43k forks source link

Dev: Colored console output #489

Open abhinav opened 7 years ago

abhinav commented 7 years ago

We should color the output under the development config for better readability in a console.

Some ideas,

akshayjshah commented 7 years ago

I'm up for this, but only if we can also do bulletproof TTY detection. I'd much rather have uncolored logs than see escape codes in non-interactive environments.

prashantv commented 7 years ago

We should use existing terminal detection, I've seen https://github.com/mattn/go-isatty before, and the Go x/ package contains one too:https://godoc.org/golang.org/x/crypto/ssh/terminal#IsTerminal

ansel1 commented 7 years ago

I'd suggest having an option to force colored output on or off (regardless of TTY detection). We have CI servers, for example, which can handle colored output nicely, but are non-interactive.

akshayjshah commented 6 years ago

I'm happy to look at PRs for this, but really don't want to depend on any pre-1.0 or unversioned libraries.

nikolavp commented 6 years ago

Isn't this fixed with the inclusion of #307?

philips commented 5 years ago

@nikolavp maybe OP is asking for CapitalColorLevelEncoder to be used by NewDevelopment by default?

akshayjshah commented 5 years ago

OP's intention was that the default interactive development experience looks less like a wall of undifferentiated text; one of the options was to enable colors by default.

Honestly, we still haven't found a solution for this that I like. Internally, our preference is to push fragile/complex-ish things like TTY detection to a config layer that's company-specific. Churn in the behavior of that package doesn't affect the stability of zap itself.

rajatsing commented 5 years ago

@akshayjshah I will be working on this. Is there something I need to keep in mind before starting out?

develar commented 5 years ago

I implemented apex-like console colored encoder (here white is used for debug, blue for info, red for error and yellow for warn).

Screenshot 2019-07-03 at 09 39 34

maybe this month I will publish as a separate reusable package.

But problem is that currently nested logger (With ) implemented in an efficient manner — instead of passing inherited fields to EncodeEntry, these fields encoded on With call and then added to final result as byte array. But colored renderer cannot work in this way, because color is not yet known (depends on level). As solution, I encode name and value to separate string (key) and byte (value) arrays. A little bit inefficient, but it is the only solution (well, the most expensive part — encode value, is done as before, so, only memory usage a little bit increased).

nikicat commented 10 months ago

Hey @develar do you have any updates on this issue?