Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

使用示例:

package main

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

func main() {
	glog.Debug(g.Map{"uid" : 100, "name" : "john"})
	type User struct {
		Uid  int    `json:"uid"`
		Name string `json:"name"`
	}
	glog.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"}