Debug with ‘tail -f dmesg’ Equivalent and ‘proc/sys/kernel/printk’ Logging

A situation presented itself today where I needed to monitor the ‘dmesg’ output continually.  This is normally easy for regular files because you can simply use the command tail -f thefile and it will always present you with the latest information.  Well, not so with the dmesg output.  If you try, you’ll be greeted with some sort of error message.  One way around this is to run the dmesg -c command in a while loop like so…

while true;do dmesg -c;done

Understand that running dmesg -c will clear the dmesg ring buffer contents after printing, so you will lose the contents of dmesg.

Now, I’m not 100% sure if that while loop is a totally elegant or acceptable solution, so I offer another solution — the /proc/sys/kernel/printk file. According to IBM.com

This holds four numeric values that define where logging messages are sent, depending on their importance. For more information on different log levels, read the manpage for syslog(2). The four values of the file are:

1. Console Log Level: messages with a higher priority than this value will be printed to the console
2. Default Message Log Level: messages without a priority will be printed with this priority
3. Minimum Console Log Level: minimum (highest priority) value that the Console Log Level can be set to
4. Default Console Log Level: default value for Console Log Level

Default setting: 6 4 1 7

By experimenting with these values, you can send printk messages directly to the terminal window instead of only to dmesg. You can set these values using

echo "9 9 9 9" > /proc/sys/kernel/printk

Happy debugging!

Source: http://www.linuxforums.org/forum
Additional Resource: http://www.de-brauwer.be/wiki

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 1 Comment So Far

  • David
    June 11th, 2011 at 6:21 am

    cat /proc/kmsg
    works for me

Share your thoughts, leave a comment!