The kernel also provides some helper functions for logging that can simplify their use. Each log level has its own function, which expands as a macro for theprintk
function. For example, when using printk
with the KERN_EMERG
log level, you can use the pr_emerg
, instead. Each macro is listed in ./linux/include/linux/kernel.h.
/* If you are writing a driver, please use dev_dbg instead */
#if defined(DEBUG)
#define pr_debug(fmt, ...) /
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#elif defined(CONFIG_DYNAMIC_DEBUG)
/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
#define pr_debug(fmt, ...) do { /
dynamic_pr_debug(fmt, ##__VA_ARGS__); /
} while (0)
#else
#define pr_debug(fmt, ...) /
({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
#endif
The syslog
call (called do_syslog
within the kernel in ./linux/kernel/printk.c) is a relatively small function that provides the ability to read and control the kernel ring buffer.
SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
{
return do_syslog(type, buf, len);
}
http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/?ca=drs-