手动清洗
- 日志为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()