系统篇: Linux 下 kernel 的打印等级

一、等级划分
#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值