How to deal with dmesg timestamps

By default dmesg command print kernel ring buffer using timestamp for each logged message. It is easy to change this behavior and display date/time in human readable form using just one additional parameter but sometimes it is not supported so I will shortly touch upon this topic.

$ dmesg
[...]
[    1.028871] Linux agpgart interface v0.103
[    1.028940] agpgart-intel 0000:00:00.0: Intel Sandybridge Chipset
[    1.028999] agpgart-intel 0000:00:00.0: detected gtt size: 2097152K total, 262144K mappable
[    1.029857] agpgart-intel 0000:00:00.0: detected 65536K stolen memory
[...]

How to convert timestamps to human readable form?

The easiest way is to use -T or --ctime parameter.

$ dmesg -T
[...]
[Sat Oct 19 12:43:26 2013] Linux agpgart interface v0.103
[Sat Oct 19 12:43:26 2013] agpgart-intel 0000:00:00.0: Intel Sandybridge Chipset
[Sat Oct 19 12:43:26 2013] agpgart-intel 0000:00:00.0: detected gtt size: 2097152K total, 262144K mappable
[Sat Oct 19 12:43:26 2013] agpgart-intel 0000:00:00.0: detected 65536K stolen memory
[...]

What if above-mentioned parameters are not supported?

Sometimes you will encounter linux distribution in which such conversion is not supported but it can be easily implemented using the following shell script.

#!/bin/bash
# Translate dmesg timestamps to human readable format

# desired date format
date_format="%a %b %d %T %Y"

# uptime in seconds
uptime=$(cut -d " " -f 1 /proc/uptime)

# run only if timestamps are enabled
if [ "Y" = "$(cat /sys/module/printk/parameters/time)" ]; then
  dmesg | sed "s/^\[[ ]*\?\([0-9.]*\)\] \(.*\)/\\1 \\2/" | while read timestamp message; do
    printf "[%s] %s\n" "$(date --date "now - $uptime seconds + $timestamp seconds" +"${date_format}")" "$message"
  done
else
  echo "Timestamps are disabled (/sys/module/printk/parameters/time)"
fi

What if timestamps are missing?

Rarely you will find that timestamps are missing from the dmesg output.

$ dmesg
[...]
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
[...]

Read /sys/module/printk/parameters/time file to confirm that timestamps are disabled.

$ cat /sys/module/printk/parameters/time
N

To enable logging timestamps write Y to the above-mentioned file.

$ echo Y | sudo tee /sys/module/printk/parameters/time
This change will not be permanent as it will last until reboot. To make it permanent add printk.time=1 parameter to grub options.

Log test message and verify dmesg output to check out changes.

$ echo "Enabled timestamps" | sudo tee /dev/kmsg
$ dmesg
[...]
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
[...]
[271309.434405] Enabled timestamps
[...]
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments (1)
Comment By DJKR - Tue, Dec 13th, 2022 4:16 PM
What timezone are the timestamps in the dmesg file If I look at the system time I see date Tue Dec 13 15:10:06 UTC 2022 however looking at the logs I see a different time date: invalid date `now - 88782715.55 seconds + lo: seconds' date: invalid date `now - 88782715.55 seconds + lo: seconds' date: invalid date `now - 88782715.55 seconds + lo: seconds' [] Disabled Privacy Extensions [] Disabled Privacy Extensions [Wed Dec 14 06:12:25 2022] Enabled timestamps [Wed Dec 14 06:13:14 2022] lo: Disabled Privacy Extensions [Wed Dec 14 06:13:14 2022] lo: Disabled Privacy Extensions
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
HowTo: Kill TCP Connections in CLOSE_WAIT State
Viewed 15481 times since Thu, Feb 14, 2019
www.unixarena.com
Viewed 2350 times since Fri, Jul 27, 2018
Tilix: Advanced Tiling Terminal Emulator for Power Users
Viewed 6304 times since Thu, Apr 18, 2019
How To Use the Linux Auditing System on CentOS 7
Viewed 3825 times since Fri, Apr 5, 2019
Use inotify-tools on CentOS 7 or RHEL 7 to watch files and directories for events
Viewed 13945 times since Fri, Jul 27, 2018
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3104 times since Tue, Aug 6, 2019
RHEL: Adding a boot entry to GRUB/GRUB2 configuration
Viewed 4508 times since Sun, May 27, 2018
RHEL7: Configure automatic updates.
Viewed 1793 times since Wed, Oct 17, 2018
BIND for the Small LAN
Viewed 3309 times since Sun, May 20, 2018
watchdog How to restart a process out of crontab on a Linux/Unix
Viewed 5893 times since Tue, Jul 31, 2018