printk

printk的日志级别定义如下(在linux/kernel.h中):

#define KERN_EMERG "<0>"/*紧急事件消息,系统崩溃之前提示,表示系统不可用*/
#define KERN_ALERT "<1>"/*报告消息,表示必须立即采取措施*/
#define KERN_CRIT "<2>"/*临界条件,通常涉及严重的硬件或软件操作失败*/
#define KERN_ERR "<3>"/*错误条件,驱动程序常用KERN_ERR来报告硬件的错误*/
#define KERN_WARNING "<4>"/*警告条件,对可能出现问题的情况进行警告*/
#define KERN_NOTICE "<5>"/*正常但又重要的条件,用于提醒。常用于与安全相关的消息*/
#define KERN_INFO "<6>"/*提示信息,如驱动程序启动时,打印硬件信息*/
#define KERN_DEBUG "<7>"/*调试级别的消息*/

使用举例:
printk(KERN_INFO "INFO\n");  //可以使用数字代替 KERN_INFO

printk(<6> "INFO\n");  //使用数字

printk("INFO\n");  //默认是4

注:

当 printk() 中的消息日志级别小于当前控制台日志级别时,printk 的信息(要有/n符)就会在控制台上显示。但无论当前控制台日志级别是何值,通过dmesg总能查看。

通过读写/proc/sys/kernel/printk文件可读取和修改控制台的日志级别。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhgAAAAtCAIAAABjzoVwAAAQLElEQVR4nO2da1saSRbH9xO12Q02KmoiGgeDoqKoEZV4IRIviY6OGHF0XJN4j7noSLxncI3G+0jUeImICgg0LbRMf43d/QKzL3q2p6eBogURgvU8vxdA0VWnz6mqf3dVdfXf5manfv/99//+598ID4VAIBAI5LL8DQoJBAKBQIIBCgkEAoFAggIKCQQCgUCCAgoJBAKBQIICCgkEAoFAgsK7kNQ1NhAkTpC4FTNdpzWVKlXDD02XPerT2iJlLUHi12ktuFxNV4fDZY00X4UUhbKKdsgtNM7zD7fjBecX9gK5HOGhO/vbTeqW6zHsSnxVWllBkHi2LD/sfo4Eq1jliiQSgsSVNaqwO4TJpXqGUHjy09ri7NxsAAf6qrGR6WcELCSZ0lzhd6LrtEY7pf11a8NrEj/5Tnfvi61dvdl+srO/3dreRiclp6YJRRndPc+vWU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3Lwd7MZfN7/tUIBDIZWELidl+YjQZlteX5A8VZVWVW7v6U4sxcjbdunJuoXHb+581nT8iPBQKSRQTg/KPzYaJ2fGwWwKBRB9sITnDTh0uK71BJrW/WxSPBrR1th8c7VIbrkAhiWIUyiqCxMuA77ODQCCBwRaSw+ODze0/38wVE8s/v7DT7yWMMhJTU224peZpPZqYhCYmlVZWECReXVfDS0gMu22h5qYJyczc9MnZEdypEAIJBWwhWVj+uLnzp5DcQuOcbqxveCDshoaCHJnM8yEDgsQPjw/CbluouVFCIhCmnl/Y+1/1h90SCCQqYQtJR/dPOGGjX7MjLSwkSLy+qTHshoYCNDFJJi+maW5TEyTe3tXBfINvtHKjhKS1vY0g8SypNOyWQCBRCVtIBMJUk/V44/NaRfUjZW3N3uGO0XR4Q978cUPmSMoqK5Q1qtHxUYLEv2/9QVmjivqFeVu7+s9f9GE3AwKJVrxskSLOzZ1fmrefW+znFt2CLl2cGXYrr4cbIiRG0yFrKK9vKJrHfLJl+QSJt3Zowm4JBBKtwE0bIRAIBBIUUEggEAgEEhRQSCAQCAQSFFBIIBAIBBIUUEggEY3XB31owm4eBAJBoJBAIhwoJBBI5AOFBBLRQCGBQCIf70JS19hANVQrZrpOaypVqoYfLr1B5Ke1xbD0LOByNV0dDpc10nwVUqiNESmo12exuB0vOL+wF8jlCA/d2d/m8spbKCQQSOTzP9dSt6PZrVLyAAAAAElFTkSuQmCC" alt="" />

分别对应控制台日志级别、默认的消息日志级别、最低的控制台日志级别和默认的控制台日志级别。

可用下面的命令设置当前日志级别:

# echo 8 > /proc/sys/kernel/printk

上一篇:javascript-为什么我们不能在applyBindings()之前调用Uniform()?


下一篇:File Transfer