代码拉取完成,页面将自动刷新
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
}
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。