Since I used dmesg for the first time I felt there was something wrong about it. Having very accurate timestamps might of course be helpful for many people, but sometimes you just want to know when something happened.
dmesg prints timestamps in the form of
seconds.nanoseconds since the system booted. And no, there seems to be no -h option to make it human readable.
Today I felt like writing some Python for that, and pydmesg is the result. Is a simple script that fetches the uptime from
/proc/uptime and uses it to print nice dmesg timestamps (timestamp format can be changed by editing the file).
[499902.343696] uvcvideo: Failed to query (1) UVC ... [499902.354633] uvcvideo: Failed to query (1) UVC ... [530442.358520] npviewer.bin: segfault at ...
[2010-08-21 13:12:37] uvcvideo: Failed to query (1) UVC ... [2010-08-21 13:12:37] uvcvideo: Failed to query (1) UVC ... [2010-08-21 21:41:37] npviewer.bin : segfault at ...
By default precision is set to the second, which I guess is ok for
human beings ;–)
8 thoughts on “pydmesg: dmesg with human readable timestamps”
Thx very much for this.BTW I had to make some improvements to this script. Some early lines are displayed with white spaces in time i.e.:[ 820.254259] process `skype’ is using obsolete setsockopt SO_BSDCOMPATSuch lines were not displayed, so I’ve changed _dmesg_line_regex to _dmesg_line_regex = re.compile(“^\[\s*(?P<time>\d+\.\d+)\](?P<line>.*)$”)Now all lines from dmesg have human readable time format.
Thanks for the correction! I’ll update the gist with it 🙂
I came across your article for converting DMESG unix time stamps into human readable format and it worked like a charm! I just cut and pasted your code into a file I created called “pydmesg”, changed permissions on the file to execute and VOILA!Thank you! Now when my SYSLOG’s roll over, and there are previous messages in DMESG, I don’t need to hunt through the SYSLOG files.Thanks again!!Bill
Many thanks, very useful script! 🙂
I came across your script while searching for a solution to this, but I also came across a much simpler solution: instead of dmesg, runtail /var/log/kern.logso instead of pydmesg, I use mydmesg defined in my .bashrc:alias mydmesg=’tail -100 /var/log/kern.log’:-)
RDuke: ideed, that could be an optin 🙂 I wrote this after playing a lot with the datetime module, so it was a “just for fun” thing 🙂
This is a really nice program. On debian, or at least on my debian, the kern.log file doesn’t have any information, so your fallback is great..
Nice, but it seems confused by timezone or uptime or something.I had an error around 2012-01-30 14:30 PST of [223281.612941] —[ end trace cc81341889dec48b ]—But your script printed it as [2012-01-29 06:02:31] —[ end trace cc81341889dec48b ]—32 hours earlier. Hmmm. Datetime is hard 😉