如何过滤掉 Ubuntu 系统日志文件中的错误?

min*_*nto 3 filesystem system error-handling logging 14.04

如何在ubunty系统日志文件中查找错误,特别是能导致各种问题的错误,证明系统损坏的错误,而不是随意的小错误。我的意思是在日志文件中搜索带有错误、损坏、失败、崩溃消息的行。哪些日志文件最重要?我安装了Glogg日志浏览器实用程序。有没有办法扫描多个日志文件并过滤掉重要的错误消息以单独文件进行分析?

Sto*_*ord 5

最简单的方法是grep在终端窗口中使用。您应该首先检查的日志文件是syslog. 所以,输入:

grep -i -e fail -e error -e corrupt /var/log/syslog

将为您提供包含您在每个-e开关后键入的关键字的所有行。该-i开关告诉grep忽略大小写。


小智 5

如今,在带有journald的Ubuntu系统上,您实际上可以根据元数据按优先级过滤所有日志,而不是通过查找可能(或可能不)暗示优先级的文本字符串。

用于journalctl显示日志。它有很多过滤选项,但发现错误的一个是:

-p, --priority=
           Filter output by message priorities or priority ranges. Takes either a single numeric or textual log level (i.e. between
           0/"emerg" and 7/"debug"), or a range of numeric/text log levels in the form FROM..TO. The log levels are the usual syslog
           log levels as documented in syslog(3), i.e.  "emerg" (0), "alert" (1), "crit" (2), "err" (3), "warning" (4), "notice" (5),
           "info" (6), "debug" (7). If a single log level is specified, all messages with this log level or a lower (hence more
           important) log level are shown. If a range is specified, all messages within the range are shown, including both the start
           and the end value of the range. This will add "PRIORITY=" matches for the specified priorities.
Run Code Online (Sandbox Code Playgroud)

因此,如果您想在所有日志中搜索任何分类为“紧急”、“警报”、“严重”或“错误”(这是 4 个最严重级别)的内容,请使用:

journalctl -p 0..3