22

I am debugging a driver for linux (specifically ubuntu server 9.04), and there are several printf statements in the code.

Where can I view the output of these statements?

EDIT1: What i'm trying to do is write to kernel using the proc file-system. The print code is

static int proc_fractel_config_write(struct file *file, const char *argbuf, unsigned long count, void *data)
{
    printk(KERN_DEBUG "writing fractel config\n");
    ...

In kern.log, I see the following message when i try to overwrite the file /proc/net/madwifi/ath1/fractel_config (with varying time of course).

[ 8671.924873] proc write 
[ 8671.924919] 

Any explainations?

apoorv020
  • 5,420
  • 11
  • 40
  • 63

7 Answers7

28

Many times KERN_DEBUG level messages are filtered and you need to explicitly increase the logging level. You can see what the system defaults are by examining /proc/sys/kernel/printk. For example, on my system:

# cat /proc/sys/kernel/printk
4       4       1       7

the first number shows the console log level is KERN_WARNING (see proc(5) man pages for more information). This means KERN_NOTICE, KERN_INFO, and KERN_DEBUG messages will be filtered from the console. To increase the logging level or verbosity, use dmesg

$ sudo dmesg -n 7
$ cat /proc/sys/kernel/printk
7       4       1       7

Here, setting the level to 7 (KERN_DEBUG) will allow all levels of messages to appear on the console. To automate this, add loglevel=N to the kernel boot parameters where N is the log level you want going to the console or ignore_loglevel to print all kernel messages to the console.

ctuffli
  • 3,559
  • 4
  • 31
  • 43
  • Log level constants are currently (since 3.6?) defined in [](http://lxr.free-electrons.com/source/include/linux/kern_levels.h) – pevik Apr 01 '14 at 16:26
13

It depends on the distribution, but many use klogd(8) to get the messages from the kernel and will either log them to a file (sometimes /var/log/dmesg or /var/log/kernel) or to the system log via syslog(3). In the latter case, where the log entries end up will depend on the configuration of syslogd(8).

One note about the dmesg command: Kernel messages are stored in a circular buffer, so large amounts of output will be overwritten.

Blrfl
  • 6,817
  • 1
  • 25
  • 25
6

You'll get the output with the command dmesg

chris
  • 3,986
  • 1
  • 26
  • 32
  • Can't find what I am looking for, but I will try again. – apoorv020 Dec 23 '10 at 12:02
  • 2
    Are they really "printf" statements? They really should be "printk", I don't think printf is defined in the kernel (please correct me if I'm wrong). – chris Dec 23 '10 at 12:14
  • It is my understanding that chris is correct. printk() will output to dmesg or /var/log/messages – cheesysam Dec 23 '10 at 12:50
5

dmesg outputs all the messages from the kernel. Finding your desired messages would be difficult. Better use dmesg and grep combination and use a driver specific label in all your printk messages. That will ease in eliminating all the unwanted messages.

printk("test: hello world")

dmesg | grep test
tshepang
  • 12,111
  • 21
  • 91
  • 136
Abhisheietk
  • 160
  • 5
1

I had this problem on Ubuntu 11.10 and 10.04 LTS, on the former I edited /etc/rsyslog.d/50-default.conf, then restarted rsyslog using "sudo service rsyslog restart" to restart rsyslogd. Then it worked.

Note that Ubuntu uses *r*syslogd, not syslogd.

Vectorio
  • 11
  • 1
0

In centos (Atleast in centos 6.6) the output will be in /var/log/messages

Thiyagarajan
  • 1,271
  • 1
  • 14
  • 19
0

You might try a higher level than KERN_DEBUG, for example KERN_INFO. Depending on your configuration the lowest priority messages might not be displayed.

Eric Seppanen
  • 5,923
  • 30
  • 24