You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

glog对日志分析工具非常友好,支持输出JSON格式的日志内容,以便于后期对日志内容进行解析分析。想要支持JSON数据格式的日志输出非常简单,给打印方法提供map/struct类型参数即可。

使用示例:

package main

import (
	"github.com/gogf/gf/frame/g"
)

func main() {
	g.Log().Debug(g.Map{"uid": 100, "name": "john"})
	type User struct {
		Uid  int    `json:"uid"`
		Name string `json:"name"`
	}
	g.Log().Debug(User{100, "john"})
}

执行后,终端输出结果:

2019-06-02 15:28:52.653 [DEBU] {"name":"john","uid":100}
2019-06-02 15:28:52.653 [DEBU] {"uid":100,"name":"john"}
  • No labels