Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does output of print in kernel go?

Tags:

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?

like image 602
apoorv020 Avatar asked Dec 23 '10 11:12

apoorv020


People also ask

How do I print kernel logs?

print everything appended to /var/log/messages: tail -f /var/log/messages. dump the logs on the serial port and read them on another PC. You will need to add to your kernel boot parameters: console=ttyS0,115200 console=tty0 ignore_loglevel and remove quiet.

How do I find the kernel log in Linux?

You can also view logs via dmesg, which prints the kernel ring buffer and sends you to the end of the file. From there, you can use the command dmesg | less to scroll through the output. If you want to view log entries for the user facility, you need to issue the command dmesg –facility=user.

How do I use printk in Linux?

printk is a C function from the Linux kernel interface that prints messages to the kernel log. It accepts a string parameter called the format string, which specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string. The string is then printed to the kernel log.

How do I enable debug prints in Linux kernel?

upon the kernel booted and the prompt appear to enable debug level messages by executing either dmesg -n 8 or echo 8 > /proc/sys/kernel/printk.


1 Answers

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.

like image 145
ctuffli Avatar answered Oct 17 '22 02:10

ctuffli