You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kratos/log
Cluas 13208d7908
fix(log): FilterFunc keyvals lost logger prefix (#1901)
3 years ago
..
README.md update contrib readme (#1831) 3 years ago
filter.go fix(log): FilterFunc keyvals lost logger prefix (#1901) 3 years ago
filter_test.go fix(log): FilterFunc keyvals lost logger prefix (#1901) 3 years ago
global.go fix: fix some typos (#1869) 3 years ago
global_test.go make logger appliance as logger proxy (#1765) 3 years ago
helper.go fix(log): call depth (#1885) 3 years ago
helper_test.go refactor: move from io/ioutil to io and os packages (#1633) 3 years ago
level.go change debug level to -1 (#1105) 3 years ago
level_test.go test: add log test (#1576) 3 years ago
log.go feat(log): log load config only when Debug level (#1899) 3 years ago
log_test.go test: add log test (#1576) 3 years ago
std.go fix: ci lint error (#1391) 3 years ago
std_test.go test: add log test (#1576) 3 years ago
value.go fix: fix some typos (#1869) 3 years ago
value_test.go test: add log test (#1576) 3 years ago

README.md

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