一、等级划分
#kernel/include/linux/kern_levels.h
#define KERN_EMERG KERN_SOH "0" /* system is unusable */
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
#define KERN_CRIT KERN_SOH "2" /* critical conditions */
#define KERN_ERR KERN_SOH "3" /* error conditions */
#define KERN_WARNING KERN_SOH "4" /* warning conditions */
#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
#define KERN_INFO KERN_SOH "6" /* informational */
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
二、终端打印级别
#kernel/include/linux/printk.h
/* We show everything that is MORE important than this.. */
#define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
#define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
#define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */
#define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */
#define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
#define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
extern int console_printk[];
#define console_loglevel (console_printk[0])
#define default_message_loglevel (console_printk[1])
#define minimum_console_loglevel (console_printk[2])
#define default_console_loglevel (console_printk[3])
#kernel/kernel/printk/printk.c
int console_printk[4] = {
CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */
MESSAGE_LOGLEVEL_DEFAULT, /* default_message_loglevel */
CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */
CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */
};
- 当优先级的值小于console_loglevel这个整数变量的值,终端才会打印出来,而console_loglevel的初始值为console_printk[0],即CONSOLE_LOGLEVEL_DEFAULT=7
三、/proc/sys/kernel/printk文件
- 一般/proc/sys/kernel/printk文件内容如下,分别对应console_loglevel、default_message_loglevel、minimum_c onsole_loglevel、default_console_loglevel,以下表示只有优先级高于KERN_DEBUG(4)的打印消息才能输出到终端
droid@droid:~$ cat /proc/sys/kernel/printk
4 4 1 7
- 修改/proc/sys/kernel/printk使得所有log都打印到终端
echo 8 > /proc/sys/kernel/printk
- 修改/proc/sys/kernel/printk使得所有log都不打印到终端
echo 0 > /proc/sys/kernel/printk