Log Cleaning

Manual cleaning

  1. Slf4j logs for the log, info level
  2. Filter out content required by shell
  3. Json resolved to form a python
// 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()

Guess you like

Origin blog.csdn.net/hvgdfx/article/details/92571602
Recommended