Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev: Colored console output #489

Open
abhinav opened this issue Aug 15, 2017 · 10 comments
Open

Dev: Colored console output #489

abhinav opened this issue Aug 15, 2017 · 10 comments

Comments

@abhinav
Copy link
Collaborator

abhinav commented Aug 15, 2017

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

Some ideas,

  • Color log lines based on levels
  • Use a muted color for stack traces belonging to vendored dependencies and
    something brighter for the main application
  • Color keys and values for key-value pairs differently
@abhinav abhinav changed the title Development: Colored console output Dev: Colored console output Aug 15, 2017
@akshayjshah
Copy link
Contributor

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
Copy link
Collaborator

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
Copy link
Contributor

ansel1 commented Aug 22, 2017

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
Copy link
Contributor

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
Copy link

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

@philips
Copy link

philips commented Nov 15, 2018

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

@akshayjshah
Copy link
Contributor

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
Copy link

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

@develar
Copy link

develar commented Jul 3, 2019

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
Copy link

nikicat commented Dec 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

9 participants