1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-05 22:53:41 +02:00
kratos/log
2021-06-24 18:04:55 +08:00
..
filter_test.go fix 2021-06-14 10:14:23 +08:00
filter.go fix log filter (#1056) 2021-06-14 21:00:18 +08:00
helper_test.go add ctx for logger (#998) 2021-06-03 16:56:55 +08:00
helper.go add log fatal level (#1067) 2021-06-16 14:53:44 +08:00
level.go change debug level to -1 (#1105) 2021-06-24 18:04:55 +08:00
log_test.go log: add level printer (#918) 2021-05-17 16:34:28 +08:00
log.go add ctx for logger (#998) 2021-06-03 16:56:55 +08:00
README.md update log/readme.md (#1085) 2021-06-20 21:23:57 +08:00
std_test.go log: add level printer (#918) 2021-05-17 16:34:28 +08:00
std.go fix log filter (#1056) 2021-06-14 21:00:18 +08:00
value_test.go log: add level printer (#918) 2021-05-17 16:34:28 +08:00
value.go fix 2021-06-14 11:12:58 +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(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")