Printing¶
printk¶
Tip
You probably shouldn't use printk, but the pr_### functions instead.
Note
The KERN_### part of the printk call is not a separate argument, it concatenates to the message.
Get current log level¶
Set current log level¶
Using sysfs:
Using dmesg:
pr_### functions¶
| Name | String | Alias function |
|---|---|---|
| KERN_EMERG | “0” | pr_emerg() |
| KERN_ALERT | “1” | pr_alert() |
| KERN_CRIT | “2” | pr_crit() |
| KERN_ERR | “3” | pr_err() |
| KERN_WARNING | “4” | pr_warn() |
| KERN_NOTICE | “5” | pr_notice() |
| KERN_INFO | “6” | pr_info() |
| KERN_DEBUG | “7” | pr_debug() and pr_devel() if DEBUG is defined |
| KERN_DEFAULT | “” | |
| KERN_CONT | “c” | pr_cont() |
pr_fmt¶
The pr_### functions utilise an internal function called pr_fmt which you can overwrite locally in your own kernel driver.
For example, you can force every message to be prepended with the module and function name, saving a lot of duplication and potential future change: