python输出json日志

python 日志包 loggus 可以非常轻易的输出 json 日志,

安装 

pip install loggus

使用可以结合具体的fields进行细例化的分割

import loggus

if __name__ == '__main__':
    loggus.SetFormatter(loggus.JsonFormatter)
    loggus.info("hello world")
    loggus.WithFields({
        "name": "cza",
        "age": 18,
    }).info("hello world")

输出日志为:

{"time": "2020-11-05 18:42:03.148269", "level": "info", "msg": "hello world"}
{"name": "cza", "age": 18, "time": "2020-11-05 18:42:03.148269", "level": "info", "msg": "hello world"}

 

源码参考:https://github.com/CzaOrz/loggus

posted @ 2020-11-05 18:46  是在下陈某人啦  阅读(360)  评论(0编辑  收藏  举报