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
时间: 2024-11-05 14:38:23