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(打印級別  “要打印的信息”)

       打印級別  既上面定義的幾個宏


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM