Is there a way to change the format of timestamp in kernel logs?

It was something like 2012-08-27T8:54:35.939421+03:00 now, I also checked sysctl -a | grep log, nothing found really.

  • jftr the timestamp are absolute numbers since boot and don't have anything to do with your system clock – Ulrich Dangel Sep 27 '12 at 9:53

No, see the kernel code in kernel/printk.c, it's hardcoded as:

sprintf(tbuf, "[%5lu.%06lu] ", (unsigned long) t, nanosec_rem / 1000)

All you can do is enable/disable that timestamp. You can have whatever reads /proc/kmsg (syslog, klog...) add the timestamp itself.

  1. in /var/log/messages and /var/log/syslog, it's automatically converted to HRTS (human readable timestamp).

  2. With -T, dmesg can return you with the HRTS form of the kernel ring. Please look at man dmesg.
    You may make a cron script to get what you exactly want :
    every $PERIOD seconds, dmesg --ctime --read-clear >> mymessagesHRTS.log

  3. You may think in using :
    dmesg --console-off
    dmesg --ctime --decode --show-delta
    (Reference : dmesg from util-linux 2.20.1)

hth - Stéphane

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.