mirror of
https://github.com/go-kratos/kratos.git
synced 2024-12-26 20:54:38 +02:00
311016862b
* feat: use writer directly in stdLogger. * fix: Add newlines for each Log * fix: remove break changes. --------- Co-authored-by: Daemon <haiyux@foxmail.com> |
||
---|---|---|
.. | ||
filter_test.go | ||
filter.go | ||
global_test.go | ||
global.go | ||
helper_test.go | ||
helper_writer_test.go | ||
helper_writer.go | ||
helper.go | ||
level_test.go | ||
level.go | ||
log_test.go | ||
log.go | ||
README.md | ||
std_test.go | ||
std.go | ||
value_test.go | ||
value.go |
Logger
Usage
Structured logging
logger := log.NewStdLogger(os.Stdout)
// fields & valuer
logger = log.With(logger,
"service.name", "hellworld",
"service.version", "v1.0.0",
"ts", log.DefaultTimestamp,
"caller", log.DefaultCaller,
)
logger.Log(log.LevelInfo, "key", "value")
// helper
helper := log.NewHelper(logger)
helper.Log(log.LevelInfo, "key", "value")
helper.Info("info message")
helper.Infof("info %s", "message")
helper.Infow("key", "value")
// filter
log := log.NewHelper(log.NewFilter(logger,
log.FilterLevel(log.LevelInfo),
log.FilterKey("foo"),
log.FilterValue("bar"),
log.FilterFunc(customFilter),
))
log.Debug("debug log")
log.Info("info log")
log.Warn("warn log")
log.Error("warn log")
Third party log library
zap
go get -u github.com/go-kratos/kratos/contrib/log/zap/v2
logrus
go get -u github.com/go-kratos/kratos/contrib/log/logrus/v2
fluent
go get -u github.com/go-kratos/kratos/contrib/log/fluent/v2
aliyun
go get -u github.com/go-kratos/kratos/contrib/log/aliyun/v2