我透過執行命令「tail -f console-20160622.log」來透過 putty 監視即時伺服器日誌,我想從 putty 控制台上產生的日誌中捕獲所有錯誤訊息。方法將我的錯誤訊息寫入文字檔案嗎?
答案1
您嘗試過使用“grep”嗎?
可以幫助您的命令如下:
tail -f console-20160622.log | grep "INFO"
GREP 將過濾日誌行並僅顯示包含「INFO」字串的日誌行
答案2
如果您使用 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