Thursday, March 6, 2008

Printk ()

Links::

Example::
printk( KERN_ERR "Failed to register device %s with major %d\n", MOD_NAME, MAJOR);

It is possible to read and modify the console loglevel using the text file
/proc/sys/kernel/printk.

The file hosts four integer values:
  • current loglevel,
  • default level for messages that lack an explicit loglevel,
  • minimum allowed loglevel
  • the boot-time default loglevel.
Writing a single value to this file changes the current loglevel to that value; thus, for example, you can cause all kernel messages to appear at the console by simply entering:



# echo 8 > /proc/sys/kernel/printk


KERN_* parameters are defined in

include/linux/kernel.h
as follows:



Macro NameNumeric Value
Description
KERN_EMERG0Used for emergency messages, usually those that precede a crash.

KERN_ALERT1A situation requiring immediate action.

KERN_CRIT2Critical conditions, often related to serious hardware or software failures.

KERN_ERR3Used to report error conditions; device drivers often use KERN_ERR to report hardware difficulties.

KERN_WARNING4Warnings about problematic situations that do not, in themselves, create serious problems with the system.

KERN_NOTICE5Situations that are normal, but still worthy of note. A number of security-related conditions are reported at this level.

KERN_INFO6Informational messages. Many drivers print information about the hardware they find at startup time at this level.

KERN_DEBUG7Used for debugging messages.