从日志文件中提取错误信息


0

我通过运行命令'tail -f console-20160622.log'监视通过putty的实时服务器日志,我想从putty控制台上生成的日志中捕获所有错误信息。是否有任何命令可以从控制台或任何其他替代方法将我的错误信息写入文本文件?

Answers:


0

你试过用“grep”吗?

可以帮助您的命令如下:

tail -f console-20160622.log | grep "INFO"

GREP将过滤日志行,只显示包含“INFO”字符串的日志行


0

如果您使用的是syslog或rsyslog,则每个文件都有一个相应的.conf文件。

if     ( \
            $msg contains 'error' and $msg contains 'OUT=' \
        and $msg contains 'SRC=' and $msg contains 'DST=' \
        and $msg contains 'PROTO='\
) \
then           -/var/log/messageshere.log

显然,您可以添加更多,更少或不同的条件。

你甚至可以登录到mysql

那么:ommysql:192.168.0.1,syslog,syslog,syslog; 模板的名称

其他选项:

# => all acpid messages for debuging (uncomment if needed):
if     ($programname == 'acpid' or $syslogtag == '[acpid]:') then \
       -/var/log/acpid

# => up to notice (skip info and debug)
if     ($programname == 'acpid' or $syslogtag == '[acpid]:') and \
       ($syslogseverity <= 5 /* notice */) \
then   -/var/log/acpid
&      ~

# Emergency messages to everyone logged on (wall)
*.emerg                                         :omusrmsg:*

# enable this, if you want that root is informed
# immediately, e.g. of logins
*.alert                                root
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.