Print time zone in server log.#12939
Conversation
|
Adding time zone without config might break scripts parsing the logs. I think it's risky. I'd prefer that we allow some config to select time format, either a custom format string or an enum of some pre-defined formats where some of them include time zone, but the default one doesn't. A problem with a custom format string for strftime is that milliseconds can't be included, so perhaps an enum with some predifined formats is preferable. A limited number of formats may also be easier to handle for scripts attempting to be independent of this config. |
|
As stated in #12932 (comment), I think the issues with strftime() are in my opinion:
But I fully agree that the default log format should be kept as is today otherwise scripts, and log shippers like fluentd, fluentbit, logstash, etc will stop working on the new redis version, the default must be backwards compatible If I have any say on this , one of the predefined formats should be I have seen implementations where the fractional seconds are omitted if they are zeros (which is legal by iso 8601) like Predefined formats that I think are useful
|
| time_t zone = server.timezone / 3600; | ||
| snprintf(buf+off,sizeof(buf)-off,"%03d %c%02ld00",(int)tv.tv_usec/1000,zone>0?'-':'+',labs(zone)); |
There was a problem hiding this comment.
You can replace that "complex" logic for calculating the offset using another call to strftime using %z :
| time_t zone = server.timezone / 3600; | |
| snprintf(buf+off,sizeof(buf)-off,"%03d %c%02ld00",(int)tv.tv_usec/1000,zone>0?'-':'+',labs(zone)); | |
| off += snprintf(buf+off,sizeof(buf)-off,"%03d",(int)tv.tv_usec/1000); | |
| strftime(buf+off,sizeof(buf),"%z",&tm); |
The linux man page for strftime documents %z:
%z The +hhmm or -hhmm numeric timezone (that is, the hour and minute offset from UTC). (SU)
unfortunately that will produce the less desirable but equally correct +0100 (no colon) instead of +01:00 (colon between hours and minutes)
There was a problem hiding this comment.
Strangely strftime does not work on my centOS 7 machine, or my arm cpu machine.. and that is why I did not use it. It does work on my macOS though. I will try to figure out what's going on.
@ecerulm Are these ISO 8601 variants defined anywhere? |
|
@zuiderkwast , You mean the names The format that I called the format that I called |
I don't think this is a problem. Redis has gone through multiple versions, and its log format has also evolved. Different versions have different log formats. For example: So scripts need to have different handling methods for different versions of Redis. In the next major version, displaying time zone information is also something that the script should adapt to. |
|
If we finally decide there will be a backwards compatibility problem, we can have a new configuration item to control whether to display time zone, and by default it is off. The point is, we want to keep everything as simple as it can. |
@soloestoy, I think redis has the same log format since Redis 3.x and now we are in Redis 7.2, so it has been the same log format for 8 years. right? correct me if I'm wrong. |
|
You can take a look at the example I provided. We made modifications to the log format in both versions 4.0 and 6.0. |
|
|
To resolve #12932
Displaying time zone in the log is very helpful in many circumstances. And as a global cloud service provider, our customers often ask which time zone the time in the log is.
#12934 is very good, but the discussion of configuration items is too complicated. I think we need to stick to the original problem. In this PR a brief solution to print time zone is proposed to meet user needs. Here we only discuss how to display time zone information to avoid complicating the issue.
Currently the implementation in this PR will result in a log format shown below.