1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-18 03:21:57 +02:00
Xudong Cai b44e47b087
refactor: optimize the code and use golangci-lint to check for any errors (#1298)
* feat: optimize the code and use golangci-lint to check for any errors

* fix: TestLogger unit test
2021-08-16 10:35:08 +08:00
..
fix
2021-06-14 10:14:23 +08:00
2021-06-14 21:00:18 +08:00
2021-06-03 16:56:55 +08:00
2021-06-24 18:04:55 +08:00
2021-05-17 16:34:28 +08:00
2021-06-03 16:56:55 +08:00
2021-06-20 21:23:57 +08:00
2021-05-17 16:34:28 +08:00
2021-05-17 16:34:28 +08:00
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")