linux内核打印级别

  1.printk()是一个内核的一个记录日志的机制,经常用来记录信息或者警告。printk可以指定输出日志的优先级,在include/linux/kern_levels.h中有相应的宏定义 

 1 #define KERN_SOH    "\001"      /* ASCII Start Of Header */  
 2 #define KERN_SOH_ASCII  '\001'  
 3   
 4 #define KERN_EMERG  KERN_SOH "0"    /* system is unusable */  
 5 #define KERN_ALERT  KERN_SOH "1"    /* action must be taken immediately */  
 6 #define KERN_CRIT   KERN_SOH "2"    /* critical conditions */  
 7 #define KERN_ERR    KERN_SOH "3"    /* error conditions */  
 8 #define KERN_WARNING    KERN_SOH "4"    /* warning conditions */  
 9 #define KERN_NOTICE KERN_SOH "5"    /* normal but significant condition */  
10 #define KERN_INFO   KERN_SOH "6"    /* informational */  
11 #define KERN_DEBUG  KERN_SOH "7"    /* debug-level messages */  
12   
13 #define KERN_DEFAULT    KERN_SOH "d"    /* the default kernel loglevel */  
14   
15 /* 
16  * Annotation for a "continued" line of log printout (only done after a 
17  * line that had no enclosing \n). Only to be used by core/arch code 
18  * during early bootup (a continued line is not SMP-safe otherwise). 
19  */  
20 #define KERN_CONT   ""  

  如果不指定优先级,这printk就使用默认的优先级,DEFAULT_MESSAGE_LOGLEVEL 在linux-3.6.10/kernel/printk.c中有定义

1 /* printk's without a loglevel use this.. */  
2 #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL  
3   
4 /* We show everything that is MORE important than this.. */  
5 #define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */  
6 #define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */

如果未对CONFIG_DEFAULT_MESSAGE_LOGLEVEL进行配置,则默认值是4

 

dmesg:分析核心产生的讯息

dmesg |more                          //输出所有的核心开机时的信息。

截取命令:cut grep

  grep:分析一行讯息,若当中有我们所需要的信息,就将该行拿出来

1、查看当前控制台的打印级别
 1 cat /proc/sys/kernel/printk 
4    4    1    7
其中第一个“4”表示内核打印函数printk的打印级别,只有级别比他高的信息才能在控制台上打印出来,既 0-3级别的信息

2、修改打印
echo "新的打印级别  4    1    7" >/proc/sys/kernel/printk

3、不够打印级别的信息会被写到日志中可通过dmesg 命令来查看

4、printk的打印级别

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

 

5、printk函数的使用

      printk(打印级别  “要打印的信息”)

       打印级别  既上面定义的几个宏

posted on 2016-07-08 08:54  白宫飘红旗  阅读(9350)  评论(0编辑  收藏  举报