1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-14 02:33:03 +02:00
kratos/log
2022-11-07 14:24:41 +08:00
..
filter_test.go fix(filter): filter out keyvals if keyFunc is provided (#2484) 2022-11-07 14:24:41 +08:00
filter.go fix(filter): filter out keyvals if keyFunc is provided (#2484) 2022-11-07 14:24:41 +08:00
global_test.go fix: typo and grammatical errors (#2368) 2022-09-19 10:39:54 +08:00
global.go fix logger caller depth (#2283) 2022-08-16 22:54:55 +08:00
helper_test.go log: fix global logger (#2034) 2022-05-24 00:40:45 +08:00
helper_writer_test.go feat(log): Helper implemented io.Writer (#1927) 2022-05-06 15:59:50 +08:00
helper_writer.go fix: typo and grammatical errors (#2368) 2022-09-19 10:39:54 +08:00
helper.go fix(log): call depth (#1885) 2022-03-18 00:03:33 +08:00
level_test.go fix(log): toString float32 precision loss and convert uint use FormatUint (#2461) 2022-10-19 15:07:58 +08:00
level.go fix(log): toString float32 precision loss and convert uint use FormatUint (#2461) 2022-10-19 15:07:58 +08:00
log_test.go test(log): increase tests coverage (#2197) 2022-07-14 20:20:38 +08:00
log.go fix: wrong order of Logger prefix kvs (#2273) 2022-08-13 13:00:43 +08:00
README.md feat: add logrus to contrib log (#2077) 2022-07-07 23:07:03 +08:00
std_test.go test: add log test (#1576) 2021-10-21 17:39:33 +08:00
std.go fix with logger (#2062) 2022-05-28 19:45:37 +08:00
value_test.go test: add log test (#1576) 2021-10-21 17:39:33 +08:00
value.go fix(log): DefaultCaller doesn't returns "pkg/file:line", it returns "file:line" now. For example, both biz/user.go and data/user.go are printed as user.go in logger. It's not clear. (#2274) 2022-08-13 13:00:02 +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