1

I have put some printk statement inside Linux kernel like this

printk(KERN_DEBUG " Hello from Kernel ");

and I am interested to record output of this command while running a.out application , like:

cp /var/log/dmesg oldLog.txt
./a.out
cp /var/log/dmesg newLog.txt
diff oldLog.txt newLog.txt

But it seems this method does not work. Both newLog.txt and oldLog.txt are kind of the same. However, I can observe "Hello from Kernel" in dmesg command output. Are you aware of an easy way to capture the log like this ?

My second question is about loglevel. I used KERN_DEBUG in the printk statement but even if I set echo 1 > /proc/sys/kernel/printk it still print Hello from kernel in the dmesg command output.

ARH
  • 1,355
  • 3
  • 18
  • 32

2 Answers2

1

It has been discussed here Where does printk() print to?

printk messages will directly go to dmesg.

Community
  • 1
  • 1
mahmood
  • 23,197
  • 49
  • 147
  • 242
1

1) printk debug statements always shows up with the dmesg command, does not matter what the loglevel is set. Debug messages can be found in /var/log/messages. 2) Loglevel is set to get the debug messages printed on the console. Even though you set highest priority log level (KERN_EMERG) to print the debug message on the console, it will not not show up in the console if X-server(GUI) is running. For getting the high priority printk messages on the console jump to console mode.

Gautham Kantharaju
  • 1,735
  • 1
  • 21
  • 24