如何在控制台中显示printk()消息? [英] How can I show printk() message in console?

查看:130
本文介绍了如何在控制台中显示printk()消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

printk()打印的信息只能在 Alt + Ctrl + F1 F7 下看到kbd>控制台.这些控制台非常难以调试,因为它们无法回滚.我正在使用KDE桌面环境和控制台终端,如何将printk()消息重定向到控制台?

The information which is printed by printk() can only be seen under Alt+Ctrl+F1 ~ F7 console. These consoles are very inconvenient for debugging since they can't roll back. I am using KDE desktop environment and console terminal, how could I redirect the printk() message to console?

推荐答案

printk 是

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

内核在文件printk.h中定义了8个日志级别.

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.

每个控制台的日志级别都称为控制台日志级别,并且任何日志级别编号小于控制台日志级别的消息都会显示在控制台上,其他消息的日志级别编号会大于或等于控制台日志级别记录在内核日志(内核缓冲区)中,可以使用命令"dmesg"进行查看.

Every console has log level called as 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".

通过查看文件/proc/sys/kernel/printk可以找到控制台日志级别

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.

日志级别4对应于KERN_WARNING.因此,具有日志级别3、2、1和0的所有消息将被显示在屏幕上以及被记录,并且具有日志级别4、5、6、7的消息仅被记录并且可以使用"dmesg"来查看.

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".

可以通过写入proc条目来更改控制台日志级别

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

现在将控制台日志级别设置为6,即KERN_INFO.

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

您要在此处打印每条消息,因此应将控制台级别设置为最高数字"8"

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 & 

cat /proc/kmsg & (Android Environment)

这篇关于如何在控制台中显示printk()消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆