1 Star 1 Fork 1

menuiis/logx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
menuis 提交于 2年前 . init
package main
import "gitee.com/menciis/logx"
func main() {
logx.SetLevel("debug")
logx.SetFormat("json", " ") // < --
// To register a custom formatter:
// golog.RegisterFormatter(golog.Formatter...)
/* Example Output:
{
"timestamp": 1591423477,
"level": "debug",
"message": "This is a message with data (debug prints the stacktrace too)",
"fields": {
"username": "kataras"
},
"stacktrace": [
{
"function": "main.main",
"source": "C:/mygopath/src/gitee.com/menciis/logx/_examples/customize-output/main.go:29"
}
]
}
*/
logx.Debugf("This is a %s with data (debug prints the stacktrace too)", "message", logx.Fields{
"username": "kataras",
}) // If more than one golog.Fields passed, then they are merged into a single map.
/* Example Output:
{
"timestamp": 1591423477,
"level": "info",
"message": "An info message",
"fields": {
"home": "https://iris-go.com"
}
"stacktrace": [...]
}
*/
logx.Infof("An info message", logx.Fields{"home": "https://iris-go.com"})
logx.Warnf("Hey, warning here")
logx.Errorf("Something went wrong!")
// You can also pass custom structs, like normally you would do.
type myCustomData struct {
Username string `json:"username"`
Email string `json:"email"`
}
logx.Fatalf("A fatal error for %s screen!", "home", logx.Fields{"data": myCustomData{
Username: "kataras",
Email: "kataras2006@hotmail.com",
}})
}
/* Manually, use it for any custom format:
golog.Handle(jsonOutput)
func jsonOutput(l *golog.Log) bool {
enc := json.NewEncoder(l.Logger.Printer)
enc.SetIndent("", " ")
err := enc.Encode(l)
return err == nil
}
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/logx.git
git@gitee.com:menciis/logx.git
menciis
logx
logx
master

搜索帮助