(OK) How can I show printk() message in konsole?


http://stackoverflow.com/questions/27903915/how-can-i-show-printk-message-in-konsole


The syntax of printk is

printk ("log level" "message", <arguments>);

kernel defines 8 log levels in the file printk.h

#define KERN_EMERG "<0>" /* system is unusable*/
#define KERN_ALERT "<1>" /* action must be taken immediately*/
#define KERN_CRIT "<2>" /* critical conditions*/
#define KERN_ERR "<3>" /* error conditions*/
#define KERN_WARNING "<4>" /* warning conditions*/
#define KERN_NOTICE "<5>" /* normal but significant condition*/
#define KERN_INFO "<6>" /* informational*/
#define KERN_DEBUG "<7>" /* debug-level messages*/

Each log level corresponds to a number and the lower the number higher the importance of the message.

The levels are useful in deciding what should be displayed to the user on the console and what should not be.

Every console has log level called as the the console log level and any message with a log level number lesser than the console log level gets displayed on the console, and other messages which have a log level number higher or equal to the console log level are logged in the kernel log(kernel buffer) which can be looked into using the command "dmesg".

The console loglevel can be found by looking into the file /proc/sys/kernel/printk

$ cat /proc/sys/kernel/printk
4 4 1 7

The first number in the output is the console log level, the second is the default log level, third is the minimum log level and fourth is the maximum log level.

Log level 4 corresponds to KERN_WARNING. Thus all the messages with log levels 3,2,1 and 0 will get displayed on the screen as well as logged and the messages with log level 4,5,6,7 only get logged and can be viewed using "dmesg".

The console log level can be changed by writing into the proc entry

$ echo "6" > /proc/sys/kernel/printk
$ cat /proc/sys/kernel/printk
6 4 1 7

Now the console log level is set to 6, which is KERN_INFO.

Here you want to print out every message so you should set your console level at highest number "8"

echo "8" > /proc/sys/kernel/printk 
tail -f /var/log/kern.log & 

or

cat /proc/kmsg & (Android Environment)

posted @   张同光  阅读(102)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示