我是靠谱客的博主 缓慢小猫咪,这篇文章主要介绍日志清洗,现在分享给大家,希望可以做个参考。

手动清洗

  1. 日志为slf4j日志,info级别
  2. 用shell筛选出需要的内容
  3. 用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()

最后

以上就是缓慢小猫咪最近收集整理的关于日志清洗的全部内容,更多相关日志清洗内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部