所以基本上我在做的是使用python腳本從apache error_log文件製作報告。什麼我處理的一個例子是:從文件中的行讀取多個子字符串
core:notice - SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
suexec:notice - AH: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
這是錯誤類型,然後尾隨文字:
[Wed Apr 13 18:33:42.521106 2016] [core:notice] [pid 11690] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Wed Apr 13 18:33:42.543989 2016] [suexec:notice] [pid 11690] AH: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
,我試着讓看起來像最終的結果。然後我需要將這個格式化的文本寫入一個新文件。
我一直在嘗試使用正則表達式來做到這一點,但這已經有好幾年了,因爲我一直使用python,並且從未使用過正則表達式。到目前爲止,我所能得到的最多的是隔離第一個(日期)部分,但我無法弄清楚如何獲得隨後的括號包圍的子字符串和尾部文本。任何和所有的幫助將不勝感激!
你能發佈一些錯誤日誌的原始樣本行嗎? – TheLazyScripter
我做到了,這就是第一塊。 [Wed Apr]等行來自日誌。 – zimty