Basic support for colorized logging#10650
Basic support for colorized logging#10650yoav-steinberg wants to merge 4 commits intoredis:unstablefrom
Conversation
|
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. |
|
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:
This PR might be an opportunity to address issues and then update the coloring scheme appropriately. |
yossigo
left a comment
There was a problem hiding this comment.
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.
|
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? |
I have indeed seen some strange warning messages in the past, I can try to collect them |
|
here is what i got, base on my understanding, did not go through the module part (not familiar with it) |
|
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. |
|
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))) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
+1 to keeping the optimization at the expense of not detecting a TTY logfile name.
|
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 |
|
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. |
|
@madolson you mean it should be an opt-in feature that should be explicitly enabled? |
|
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. |
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)
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)
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)
|
|




This colorizes the "level char" at the beginning of each log line when outputting to a TTY.


And on a bright background:
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.