日志
日志来自 zerolog
Basic
package main
import (
"github.com/langwan/langgo"
"github.com/langwan/langgo/components/hello"
)
func main() {
langgo.Run(&hello.Instance{Message: "hello langgo"})
langgo.Logger("app", "hello").Info().Str("message", hello.Get().Message).Send()
}
使用 langgo.Logger()
方法输出日志信息。"app" 是文件名,"main" 是日志的标签。其它使用方法和zerolog 相同。
App (root)
└─ logs
└─ app.log
多日志文件
package main
import (
"github.com/langwan/langgo"
"github.com/langwan/langgo/components/hello"
"github.com/langwan/langgo/components/sqlite"
)
func main() {
langgo.Run(&hello.Instance{Message: "hello langgo"}, &sqlite.Instance{Path: "./database.db"})
langgo.Logger("app", "hello").Info().Str("message", hello.Get().Message).Send()
var i int64
sqlite.Get().Raw("SELECT 1").Scan(&i)
langgo.Logger("db", "main").Debug().Int64("i", i).Send()
}
App (root)
└─ logs
└─ app.log
└─ db.log
Last updated