2020-07-15 上海
dmesg命令用来输出linux内核的相关日志信息
man page: dmesg - print or control the kernel ring buffer
日志内容保存在文件: /var/log/dmesg
内核的日志也有对应的日志级别,可以在日志内容输出的时候使用--level=xx1,xxx2
格式来控制
日志级别 | 描述 | 对应命令的参数值 |
---|---|---|
LOG_EMERG | system is unusable | emerg |
LOG_ALERT | action must be taken immediately | alert |
LOG_CRIT | critical conditions | crit |
LOG_ERR | error conditions | err |
LOG_WARNING | warning conditions | warn |
LOG_NOTICE | normal, but significant, condition | notice |
LOG_INFO | informational message | info |
LOG_DEBUG | debug-level message | debug |
比如,输出emerge和error级别的日志,可以使用如下命令:
dmesg --level=error,emerg
通常,主要将dmesg的输出结合grep来进行过滤查询问题,
比如了解内存问题,可以使用如下命令:
dmesg | grep -i memory
参数 | 说明 |
---|---|
-T | 输出已读的时间戳 |
-u | 控制输出用户空间的日志 |
-c | 清除dmesg日志,但是日志保存的位置内容不会被删除 |
[root@107 ~]# dmesg -h
Usage:
dmesg [options]
Options:
-C, --clear clear the kernel ring buffer
-c, --read-clear read and clear all messages
-D, --console-off disable printing messages to console
-d, --show-delta show time delta between printed messages
-e, --reltime show local time and time delta in readable format
-E, --console-on enable printing messages to console
-F, --file <file> use the file instead of the kernel log buffer
-f, --facility <list> restrict output to defined facilities
-H, --human human readable output
-k, --kernel display kernel messages
-L, --color colorize messages
-l, --level <list> restrict output to defined levels
-n, --console-level <level> set level of messages printed to console
-P, --nopager do not pipe output into a pager
-r, --raw print the raw message buffer
-S, --syslog force to use syslog(2) rather than /dev/kmsg
-s, --buffer-size <size> buffer size to query the kernel ring buffer
-T, --ctime show human readable timestamp (could be
inaccurate if you have used SUSPEND/RESUME)
-t, --notime don't print messages timestamp
-u, --userspace display userspace messages
-w, --follow wait for new messages
-x, --decode decode facility and level to readable string
-h, --help display this help and exit
-V, --version output version information and exit
Supported log facilities:
kern - kernel messages
user - random user-level messages
mail - mail system
daemon - system daemons
auth - security/authorization messages
syslog - messages generated internally by syslogd
lpr - line printer subsystem
news - network news subsystem
Supported log levels (priorities):
emerg - system is unusable
alert - action must be taken immediately
crit - critical conditions
err - error conditions
warn - warning conditions
notice - normal but significant condition
info - informational
debug - debug-level messages
For more details see dmesg(q).
[root@107 ~]# dmesg -H
[Jun13 21:27] Linux version 5.5.2-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)) #
[ +0.000000] Command line: BOOT_IMAGE=/vmlinuz-5.5.2-1.el7.elrepo.x86_64 root=UUID=3437f1a0-f850-4f1b-8a7c-819c5f6a29e4 ro crashke
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[root@107 ~]# dmesg -H
[root@107 ~]#