Since it’s a Linux question, I’ll note I’m using OpenSUSE 12.1
I’m running a kernel module, basically it’s a CAN bus simulator, and it prints messages via printk() whenever there is activity on the ‘bus’.
I’m tracing the messages right now with sudo cat /proc/kmsg, but when I start putting other “devices” on the “bus” the kmsg traffic is greatly incressed and it’s hard to find my messages.
Is there anyway to pipe the “printk” messages from one specific process to a file?
EDIT
I see now there are possibilties if I add specific tags to my debug messages, are there any other ways?
yes, you can. All kernel messages can hold syslog-ng daemon. For this daemon you can write custom rules and put all messages from your module to specific file. Take first look at /etc/syslog-ng/syslog-ng.conf
update
By default, all kernel print and printk functions put messages to kernel ring buffer. Userspace programs can access to this ring buffer thought /proc/kmsg file.
Syslog-ng will read data from /proc/kmsg, then, via filter (filter is just special pattern) grep output and put data in different output (in this example it will be just text files). If in output buffer we will find output from kernel module “hello”, syslog-ng will put messages to /var/log/hello, all other messages will go to /var/log/messages
Module source
After insmod
in /var/log/messages you can find:
ok, lets configure syslog-ng to catch grep log message (by using pattern [hello])
$cat /etc/syslog-ng/syslog-ng.conf