How to change the system default date format to ISO 8601?

Colin Watson cjwatson at ubuntu.com
Mon Feb 5 11:42:41 UTC 2024


On Mon, Feb 05, 2024 at 10:04:33AM +0100, Bo Berglund wrote:
> I have two Ubuntu Servers, one is 20.04 LTS and the other is 22.04 LTS.
> 
> Both of them are set to Swedish time zone, but when I look at log files the
> timestamps are almost unreadable for me looking like this:
> 
> Mon Feb  5 09:42:42 2024
> 
> How can I change this stupid way of showing timestamps to instead be like
> ISO-8601:
> 
> 2024-02-05 09:42:42

Which log files?  This question matters because I'm afraid not all
programs use the same mechanism for writing to log files.

Log files that are written by rsyslog (e.g. /var/log/syslog) use
RFC3339-style timestamps by default, which aren't exactly the same as
what you describe above but are pretty similar and are still sortable.

If the log output for the program you're interested in goes through the
systemd journal (which is often the case even if it also ends up in a
log file), then you can use something like "journalctl -o short-iso -u
foo.service" to show journal entries with the timestamp format you
prefer.  I recommend learning how the systemd journal system works -
it's very useful.

If the log file is written directly by the service (for example, Apache
is like this), then you'll need to consult documentation for the service
in question.

-- 
Colin Watson (he/him)                              [cjwatson at ubuntu.com]




More information about the ubuntu-users mailing list