生活随笔
收集整理的這篇文章主要介紹了
日志清洗
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
手動清洗
日志為slf4j日志,info級別用shell篩選出需要的內容用python解析成json格式
// grep 提取關鍵詞日志
grep
-E
"A|B" > result
.txt
// python 解析
import sys
import re
import jsonfileName
= sys
.argv
[1]def read():print(fileName
)with open(fileName
, "r") as f
:with open("data_2019-06-16_result.json", "w") as f1
:count
= 1for line
in f
.readlines
():splits
= re
.split
(",|\s", line
)adict
= {field
.split
(":")[0]: field
.split
(":")[1] if len(field
.split
(":"))==2 else 0 for field
in splits
}f1
.write
(json
.dumps
(adict
))f1
.write
("\n")if count
%10000 == 0:print "this is the " + str(count
) + " line..."count
+= 1if __name__
== "__main__":read
()
總結
以上是生活随笔為你收集整理的日志清洗的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。