1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-22 03:38:41 +02:00
ionling ff105d5bca
fix(log): WithContext() changed the ctx field of the parent log.Filter (#3069)
* fix(log): `WithContext()` changed the ctx field of the parent log.Filter

* test(log): add concurrence test for `WithContext()`

* fix(log): concurrence problem of `Filter`

---------

Co-authored-by: 包子 <baozhecheng@foxmail.com>
2023-11-22 11:35:58 +08:00
..
2022-08-16 22:54:55 +08:00
2022-05-28 19:45:37 +08:00
2021-10-21 17:39:33 +08:00

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