golang 代码:
package main
import "github.com/sirupsen/logrus"
func main() {
logrus.WithFields(logrus.Fields{"name": "cc"}).Info("hello")
}
输出:
time="2020-11-06T14:50:17+08:00" level=info msg="hello" name=cc
这段日志中可以看到,拆离出了各种结构化信息,以前都没这样想过...而且输出 json 也非常方便
logrus
loggus
import loggus
if __name__ == '__main__':
loggus.WithFields({"name": "cc"}).Info("hello")
loggus.SetFormatter(loggus.JsonFormatter)
loggus.WithFields({"age": 18}).Info("world")
输出:
time="2020-11-06 14:54:15.416516" level=info msg=hello name=cc
{"age": 18, "time": "2020-11-06 15:05:04.613234", "level": "info", "msg": "world"}
等我找个内部项目试试水先,有大佬给点意见嘛,写的太简陋了...
https://github.com/CzaOrz/loggus