首页 > Windows开发 > 详细

Kernel logging: APIs and implementation

时间:2015-12-21 23:22:30      阅读:391      评论:0      收藏:0      [点我收藏+]

Kernel API

Logging within the kernel is performed using the printk function

int printk( const char * fmt, ... );
The kernel code simply defines the log level as the first argument of the message, as illustrated in the following example for a critical message:
printk( KERN_CRIT "Error code %08x.\n", val );

Note that the first argument is not an argument at all, as no comma (,) separates the level (KERN_CRIT) from the format string.

Table 1. Log levels, symbolics, and uses
Symbolic String Usage
KERN_EMERG <0> Emergency messages (precede a crash)
KERN_ALERT <1> Error requiring immediate attention
KERN_CRIT <2> Critical error (hardware or software)
KERN_ERR <3> Error conditions (common in drivers)
KERN_WARNING <4> Warning conditions (could lead to errors)
KERN_NOTICE <5> Not an error but a significant condition
KERN_INFO <6> Informational message
KERN_DEBUG <7> Used only for debug messages
KERN_DEFAULT <8> Default kernel logging level
KERN_CONT <9> Continuation of a log line (avoid adding new time stamp)

Note that if a caller does not provide a log level within printk, a default of KERN_WARNING is automatically used.

At this point, you‘ve explored the API used to insert log messages into the kernel ring buffer. Now, let‘s look at the method used to migrate data from the kernel into the host.

## Printk source code

Kernel logging and interface

Access to the log buffer is provided at the core through the multi-purpose syslog system call.

The syslog call serves as the input/output (I/O) and control interface to the kernel‘s log message ring buffer.

User space applications

 

References

Technorati 标签: ,

Kernel logging: APIs and implementation

原文:http://www.cnblogs.com/luckysimple/p/5065035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!