Skip to content

Basic support for colorized logging#10650

Open
yoav-steinberg wants to merge 4 commits intoredis:unstablefrom
yoav-steinberg:colorized_logging
Open

Basic support for colorized logging#10650
yoav-steinberg wants to merge 4 commits intoredis:unstablefrom
yoav-steinberg:colorized_logging

Conversation

@yoav-steinberg
Copy link
Contributor

@yoav-steinberg yoav-steinberg commented Apr 27, 2022

This colorizes the "level char" at the beginning of each log line when outputting to a TTY.
image
And on a bright background:
image

I'd be happy to hear any suggestions for improvements, since this is pretty minimal. But even coloring this single char makes reading the log from a console output much easier in my opinion.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder how this would play with someone who configured his terminal to have a white background?
info type will not be visible?

@yossigo can you think of any other concerns?

@yoav-steinberg
Copy link
Contributor Author

i wonder how this would play with someone who configured his terminal to have a white background? info type will not be visible?

gnome-terminal "White on black" scheme:
image
gnome-terminal "Solarized light" scheme:
image

@oranagra
Copy link
Member

so the verbose is barely visible. i.e. if we would have colored the entire line, or just the timestamp, that text will be unreadable.

@yoav-steinberg
Copy link
Contributor Author

Updated coloring:
image
image

@yoav-steinberg
Copy link
Contributor Author

An issue that came up while working on this is related to the current use of log levels and how effective they currently are in detecting issues. Once we got the colors we started noticing that some log lines might actually benefit from a different level so not to be mixed up visually with other more/less important lines. Specifically:

  • We have cases where we print information (might be important but by no means an error indicator) with the LL_WARNING level. Maybe we should demote these to LL_NOTICE:
    • oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    • User requested shutdown...
  • This is also true for cases that we encounter a rare but normal situation. Maybe here we should too demote to LL_NOTICE. Examples:
    • AOF was enabled but there is already another background operation. An AOF background was scheduled to start when possible.
    • Connection with master lost.
  • There are cases where we encounter a critical issue, leading to closing the server or hinting we're in a degraded mode of operation or possibly a bug which are logged as LL_WARNING but we might want to elevate them to some LL_ERROR or LL_CRITICAL so they'll stick out in the log:
    • CRITICAL ERROR: User ACLs don't match final bitmap: '%s'
    • Failed restoring failed CONFIG SET command. Error setting %s to '%s': %s
    • "WARNING overcommit_memory is set to 0!

This PR might be an opportunity to address issues and then update the coloring scheme appropriately.

Copy link
Collaborator

@yossigo yossigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of coloring logs at the source, but as long as we do that only on TTYs and maybe after validating the TERM environment variable is sane, I'm OK with that.

Discussed quickly with @oranagra the idea of creating a new "error" log level. I think it's going to be a lot of work because it seems like a big portion of the current warnings are really errors. Also, there would be more backwards compatibility issues, module support, etc.

The alternative of demoting some of the non-warning messages to notice makes sense to me, and should have minimal impact on users who use default config (loglevel notice). That said, I think it's still technically a breaking change - as a user I'd hate to spend a long time troubleshooting an issue only to discover the newly upgraded versions hides warnings I'm used to see.

@oranagra
Copy link
Member

ok, so we need someone with some spare time, to go over all the LL_WARNING usages and evaluate which ones should be demoted. any volunteers?

@enjoy-binbin
Copy link
Contributor

go over all the LL_WARNING usages and evaluate which ones should be demoted

I have indeed seen some strange warning messages in the past, I can try to collect them

@enjoy-binbin
Copy link
Contributor

here is what i got, base on my understanding, did not go through the module part (not familiar with it)
2cb9af3

@oranagra
Copy link
Member

thank you @enjoy-binbin , i took a look. most of them seem ok with that plan, i commented on a few i wasn't sure about.
let's make a PR and i'll transfer my comments to it so that it'll easier to collaborate on it.

@oranagra
Copy link
Member

I went over all the LL_WARNING usages in module.c, they all seem valid (don't need any change IMHO)

src/server.c Outdated
}
fprintf(fp,"%d:%c %s %c %s\n",
(int)getpid(),role_char, buf,c[level],msg);
if (isatty(fileno(fp))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's check if there's any performance implication to calling isatty, and consider caching it or at the very least doing it only when log_to_stdout is set?

Copy link
Contributor Author

@yoav-steinberg yoav-steinberg May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isatty() performs a system call (on Linux) which has a noticeable performance impact. I'll cache it (but just for stdout) since the current code doesn't assume an immutable log file name and calls open() per log, so it doesn't feel right to cache it between open()s.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it even be that we use open() on a file name and it's a TTY?
i don't think so, so there's no need to call it at all in that case.
look like that's what you did, but your comment indicated otherwise so asking..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory someone could do redis-server --logfile /dev/stdout or even redis-server --logfile /dev/tty. I can't think of a good reason to do that, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, right..
well, so they'll get what they deserve (no colors)
unless there's a good reason to do that (in which case they don't deserve it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to keeping the optimization at the expense of not detecting a TTY logfile name.

@oranagra
Copy link
Member

since this is not a bug fix or an important improvement, and it could in theory cause some unexpected issues, we decided to push this back to 7.2

@madolson
Copy link
Contributor

I don't feel all that strongly, but I want to +1 to I don't see a lot of value in trying to color the output outside of a config option. I really just don't want it on by default.

@oranagra
Copy link
Member

@madolson you mean it should be an opt-in feature that should be explicitly enabled?
chances are that no one will bother so we don't gain anything by this "feature".
why don't you want it by default? is it harmful in your opinion?

@madolson
Copy link
Contributor

I personally just find coloring annoying unless I am the one configuring it. When I'm interactively running redis I'm usually greping the log for something specific, this isn't going to show up in the logs so it doesn't matter there. It might draw attention if you do something wrong to a specific line for a warning, but outside of that I would rather just keep it clean and simple.

oranagra pushed a commit that referenced this pull request Feb 19, 2023
We have cases where we print information (might be important but by
no means an error indicator) with the LL_WARNING level.
Demoting these to LL_NOTICE:
- oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
- User requested shutdown...

This is also true for cases that we encounter a rare but normal situation.
Demoting to LL_NOTICE. Examples:
- AOF was enabled but there is already another background operation. An AOF background was scheduled to start when possible.
- Connection with master lost.


base on yoav-steinberg's #10650 (comment)
and yossigo's #10650 (review)
odaiwa pushed a commit to odaiwa/redis that referenced this pull request Feb 20, 2023
We have cases where we print information (might be important but by
no means an error indicator) with the LL_WARNING level.
Demoting these to LL_NOTICE:
- oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
- User requested shutdown...

This is also true for cases that we encounter a rare but normal situation.
Demoting to LL_NOTICE. Examples:
- AOF was enabled but there is already another background operation. An AOF background was scheduled to start when possible.
- Connection with master lost.


base on yoav-steinberg's redis#10650 (comment)
and yossigo's redis#10650 (review)
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
We have cases where we print information (might be important but by
no means an error indicator) with the LL_WARNING level.
Demoting these to LL_NOTICE:
- oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
- User requested shutdown...

This is also true for cases that we encounter a rare but normal situation.
Demoting to LL_NOTICE. Examples:
- AOF was enabled but there is already another background operation. An AOF background was scheduled to start when possible.
- Connection with master lost.


base on yoav-steinberg's redis#10650 (comment)
and yossigo's redis#10650 (review)
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

7 participants