全部博文(120)
分类: LINUX
2008-05-06 18:07:17
Printk的loglevel和日志记录分析
(分析版本是ubuntu7.10,内核源码是
首先,printk有8个loglevel,定义在
#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 */ 调试信息
从这里也可以看出他们的优先级是数值越小,其紧急和严重程度就越高。
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/printk.c中:
/* printk's without a loglevel use this.. */
#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */
/* We show everything that is MORE important than this.. */
#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */
int console_printk[4] = {
DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */ 终端级别
DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */默认级别
MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */让用户使用的最小级别
DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */默认终端级别
};