手动清洗
- 日志为slf4j日志,info级别
- 用shell筛选出需要的内容
- 用python解析成json格式
// grep 提取关键词日志
grep -E "A|B" > result.txt
// python 解析
import sys
import re
import json
fileName = 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 = 1
for 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 += 1
if __name__ == "__main__":
read()
最后
以上就是缓慢小猫咪最近收集整理的关于日志清洗的全部内容,更多相关日志清洗内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复