1 Star 1 Fork 1

menuiis/logx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
menuis 提交于 2年前 . init
package main
import "gitee.com/menciis/logx"
func main() {
logx.Child("Router").Infof("Route %s regirested", "/mypath")
// registerRoute("/mypath")
logx.Child("Router").Warnf("Route %s already exists, skipping second registration", "/mypath")
logx.Error("Something went wrong!")
var (
srvLogger = logx.Child("Server")
app1Logger = srvLogger.Child("App1")
// Or use a pointer as child's key and append the prefix manually:
app2 = newApp("App2")
app2Logger = srvLogger.Child(app2).
SetChildPrefix(app2.Name).
SetLevel("debug")
// Or use a pointer to a value which implements the fmt.Stringer:
app3 = newAppWithString("App3")
app3Logger = srvLogger.Child(app3)
)
srvLogger.Infof("Hello Server")
app1Logger.Infof("Hello App1")
app2Logger.Debugf("Hello App2")
app3Logger.Warnf("Hello App3")
srvLogger.LastChild().Infof("Hello App3 again")
}
type app struct {
Name string
}
func newApp(name string) *app {
return &app{Name: name}
}
type appWithString struct {
name string
}
func newAppWithString(name string) *appWithString {
return &appWithString{name: name}
}
func (app *appWithString) String() string {
return app.name
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/logx.git
git@gitee.com:menciis/logx.git
menciis
logx
logx
master

搜索帮助