int printk(const char *fmt, …)
works very much like int printf(const char *fmt, …)
, with one notable exception.
The first parameter to printk
can be replaced with an integer value, which is called the log level
. This decides where the message goes, which can be to the kernel's log book (a 16kb memory block; see dmesg
), or to the console.
The levels normally range from 0 (emergency; system unusable) to 7 (debugging), and are controlled by the constants KERN_EMERG, KERN_ALERT, KERN_CRIT, KERN_ERR, KERN_WARNING, KERN_NOTICE, KERN_INFO and KERN_DEBUG.
The compile-time flag CON_ENABLED is used when compiling the printk function to enable logging to the console. If set, and a console driver is loaded, then any message printed over the value of console_loglevel
will be write()n
to the console driver. The syslog()
system call changes the console loglevel, which is normally done from user space when debugging a module; the default value is 7.
long sys_syslog(int type, char *buf, int len)
can be 6 (sets the loglevel to 1), 7 (sets the loglevel to 7) or 8 (sets the loglevel to len
, which must be between 0 and 9. Returns 0; I think buf
is ignored (otherwise set it to log_start+log_size
, which I think are globals).