1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-14 02:33:03 +02:00
kratos/log
2022-03-30 08:55:48 +08:00
..
filter_test.go fix(log): FilterFunc keyvals lost logger prefix (#1901) 2022-03-30 08:55:48 +08:00
filter.go fix(log): FilterFunc keyvals lost logger prefix (#1901) 2022-03-30 08:55:48 +08:00
global_test.go make logger appliance as logger proxy (#1765) 2022-01-14 13:16:25 +08:00
global.go fix: fix some typos (#1869) 2022-03-09 10:51:17 +08:00
helper_test.go refactor: move from io/ioutil to io and os packages (#1633) 2021-11-16 13:22:35 +08:00
helper.go fix(log): call depth (#1885) 2022-03-18 00:03:33 +08:00
level_test.go test: add log test (#1576) 2021-10-21 17:39:33 +08:00
level.go change debug level to -1 (#1105) 2021-06-24 18:04:55 +08:00
log_test.go test: add log test (#1576) 2021-10-21 17:39:33 +08:00
log.go feat(log): log load config only when Debug level (#1899) 2022-03-29 16:39:31 +08:00
README.md update contrib readme (#1831) 2022-02-21 18:37:20 +08:00
std_test.go test: add log test (#1576) 2021-10-21 17:39:33 +08:00
std.go fix: ci lint error (#1391) 2021-08-31 10:14:57 +08:00
value_test.go test: add log test (#1576) 2021-10-21 17:39:33 +08:00
value.go fix: fix some typos (#1869) 2022-03-09 10:51:17 +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

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