Loglevel

From Vertubleu

Jump to: navigation, search

Contents

Linux Loglevel configuration

Complementary information can be found here: http://www.elinux.org/Kernel_Debugging_Tips

printk

A printk in the kernel generates an ouput in the console depending on the kernel loglevel configuration.

A loglevel can be passed to printk:

printk(LOGLEVEL_VALUE "trace string", args ...);

(notice that there are no comma between the loglevel and the trace string)

Depending on the loglevel value passed to printk, and on the kernel configuration, the trace string will be output to the console or not.

Note that if no loglevel is passed to printk, a default log-level is applied to the message and the filtering happens anyway at display time.

Loglevel definition

The loglevels are defined in kernel.h:

#define	KERN_EMERG	"<0>"	/* system is unusable			*/
#define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
#define	KERN_CRIT	"<2>"	/* critical conditions			*/
#define	KERN_ERR	"<3>"	/* error conditions			*/
#define	KERN_WARNING	"<4>"	/* warning conditions			*/
#define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
#define	KERN_INFO	"<6>"	/* informational			*/
#define	KERN_DEBUG	"<7>"	/* debug-level messages			*/

loglevel configuration

Enabling all traces at startup

Folowing parameters can be passed to the kernel command line to influence the loglevel:

debug - the threshold for output traces (console_loglevel - see below) is set to 10 (so all traces shall output).

loglevel= followed by the targetted loglevel

Enabling a specific log level at startup

The following parameter can be added to the kernel command-line:

loglevel=<level of the trace>

kernel syslog configuration

The syslog configuration can be read this way:

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

The configuration can be updated this way:

echo 10 4 1 7 > /proc/sys/kernel/printk

Here is a capture of the proc man-page about /proc/sys/kernel/printk. The four values in this file are:

  1. console_loglevel,
  2. default_message_loglevel,
  3. minimum_console_level
  4. default_console_loglevel

These values influence printk() behavior when printing or logging error messages. See syslog(2) for more info on the different loglevels:

  1. Messages with a higher priority than console_loglevel will be printed to the console.
  2. Messages without an explicit Priority will be printed with priority default_message_level.
  3. minimum_console_loglevel is the minimum (highest) value to which console_loglevel can be set.
  4. default_console_loglevel is the default value for console_loglevel.

Note that with a console_loglevel=7, the KERN_DEBUG (level 7) will not be output to the console.

Personal tools