码迷,mamicode.com
首页 > Windows程序 > 详细

Kernel logging: APIs and implementation

时间:2015-12-21 23:23:49      阅读:292      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!