by doctor_eval · 6y ago · 0 comments
In my experience most people, including most developers but perhaps excluding many HN readers, don't understand what the timezone setting does. The time on all contemporary computers is always Unix Epoch Time, which is close to (but not exactly) UTC. Setting your timezone doesn't actually change anything about how time works on the computer. It just changes how time is printed. That's it.
So the second problem is that our text-based server world, for all its benefits, doesn't cope well with per-user parameters. I mean ... timezone support on Unix is basically buggy. It doesn't matter what TZ I set in my .profile, nevertheless the timezone of logs is in whatever TZ the server is running in. That's pretty stupid. And even simple calculations like "how many seconds elapsed between this log entry and this one" - which is really common - are very difficult, regardless of the TZ setting.
In my own personal perfect world, all logs would be printed in the first column of log files using the epoch time in seconds, and we'd have a command which would convert from the epoch time to the local timezone. So we could do something like:
tail -f /var/log/messages | grep 'panic' | timestamp
...in which case I would be able to choose the timezone and format of the timestamps to meet the needs of the job i was doing.So for me, this whole argument over UTC is dumb. It doesn't matter what timezone the system is set to; any zone can be "default". The real problem is that different users have different time formatting requirements, and to date we haven't had tools which deal with that properly.
(even logging all timestamps consistently in ISO format would be a big step up...)
For a small number of input formats `ts` from Joey Hess' moreutils¹ can do this. Its `-r` option pulls dates out of its input and reformats them, either as a relative timestamp by default(33m57s ago) or a user-specified format if given.
Your example becomes `tail | grep | ts -r %FT%T` or something like that.
It supports syslog format, a subset of ISO-8601, and a few others. It doesn't support epoch in seconds though, but Joey is nice to interact with if you were to offer a patch.
---
This, among other reasons, is why I like all my logging going through systemd's journal nowadays. With journalctl you have a good choice of output options for date formatting or dumping as JSON if you want more.
I think the insistence on UTC is a case of "a little knowledge". What happens is some developer somewhere has to learn the hard way about time zones. Now he could either learn about the problem in depth or he finds the shortcut solution: just use UTC. He's now unlikely to ever get bitten again, but he never really learnt what the problem was. He now tells other developers to use UTC and many will blindly follow.
In that way it's a bit like the whole insistence on spaces over tabs. Another instance of "a little knowledge" and losing the power of the tab character as a result.
Now, as Europe got some sanity and will abandon time shifts the next year, local time as long as as it comes with time zone will be OK. But out of habit I guess I will continue to configure servers to use UTC.
Unfortunately it is Unix time that has a real discontinuity. This happens around leap seconds when Unix time will jump backwards or forwards by a whole number of seconds. This is actually the fault of UTC, though. Leap seconds are an abomination. Unix had the right idea all along which is to just count a number of seconds since an epoch and not worry about the movements of the solar system.
It's gotten so bad that I've made binary [1] and text [2] formats that handle all cases and have sane defaults (yes, even ISO8601 gets it wrong).
A time value without accompanying time zone data is just a bug waiting to happen. Once you add unambiguous timezone information to the time structure, getting correct time information every time is just a matter of making conversion libraries for language X. No more guesswork, no more bugs.
[1] https://github.com/kstenerud/compact-time/blob/master/compac...
[2] https://github.com/kstenerud/concise-encoding/blob/master/ct...
What the GP is suggesting is exactly doing the same thing for time. If the internal format is always UTC, that doesn't mean timezones are going away for the user, just that they shouldn't show up in the data layer.
https://infiniteundo.com/post/25326999628/falsehoods-program...
Another problem with ISO8601 is that omitting the time zone info implies floating time rather than UTC time, and this causes no end of bugs in all implementations.
When I finally gave up on it, I came up with the following alternative:
Time zone data omitted (implies UTC):
2019-01-23/14:08:51.941245 = January 23, 2019, at 14:08:51 and 941245 microseconds, UTC
Area/location based timezone:
1985-10-26/01:20:01.105/America/Los_Angeles = October 26, 1985, at 1:20:01 and 105 milliseconds, Los Angeles time
Latitude/longitude based timezone:
5192-11-01/03:00:00/48.86/2.36 = November 1st, 5192, at 3:00:00, at whatever is in the place of Paris at that time
Sure, but the only thing users normally see is that printed representation. What's the actual problem you see here?
> I mean ... timezone support on Unix is basically buggy. It doesn't matter what TZ I set in my .profile, nevertheless the timezone of logs is in whatever TZ the server is running in.
I don't see what's buggy there. If you set a TZ in your .profile, logs produced by processes within the context of that .profile will be in your desired timezone. Processes outside that context look at the system timezone, configured using /etc/localtime.
The UTC system time crowd basically just wants all logs (that don't explicitly specify further) to be in a standard timezone that does not move, so that it can be reasoned about without a lot of context. Your perfect world with an epoch time in the first column does exactly that, with the downside of not meaning anything to a human without the timestamp-conversion command.
I agree we need better tools to deal with timestamps after the fact.
So my ideal would be to be able to set TZ and see logs in TZ time.
My ideal, to use epoch time instead of local time in logs, is because in a large number of cases I'm more interested in the relative time of log entries than the absolute time. Computing relative time (seconds intervals) between log entries is error prone.
I suppose in a sense I'm in both the UTC and non-UTC camp. On reflection, I agree that server logs should be in UTC. I just don't think I should have to read them in UTC or personally operate in UTC.
The ts tool mentioned above sounds perfect, and I'm gonna start playing with it...
[1] http://smarden.org/runit/svlogd.8.html
I think Windows computers set the hardware clock to local time by default, actually.
Windows, Linux, macOS, all set the timezone value to 0x07FF which is defined as EFI_UNSPECIFIED_TIMEZONE which is to be treated as local time (but without a timezone).
In effect, it's the same mess as BIOS. It shows how specs can just be thwarted.
This applies to e.g. Linux.
But the RTC in your computer might store localtime. I do recommend using UTC there no matter what. If dual-booting windows, this needs a little extra work[0].
[0]: https://wiki.archlinux.org/index.php/System_time#UTC_in_Wind...