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
freezeChen 3445f3ea8e
fix: logging middle don't get trace_id value when logger is filterLogger (#2869)
1 year ago
..
README.md feat: add logrus to contrib log (#2077) 2 years ago
filter.go fix: logging middle don't get trace_id value when logger is filterLogger (#2869) 1 year ago
filter_test.go fix: logging middle don't get trace_id value when logger is filterLogger (#2869) 1 year ago
global.go fix logger caller depth (#2283) 2 years ago
global_test.go fix: typo and grammatical errors (#2368) 2 years ago
helper.go feat: log helper support sprint option (#2616) 2 years ago
helper_test.go fix: rectification of non-standard lint codes (#2746) 2 years ago
helper_writer.go fix: typo and grammatical errors (#2368) 2 years ago
helper_writer_test.go feat(log): Helper implemented io.Writer (#1927) 3 years ago
level.go fix(log): toString float32 precision loss and convert uint use `FormatUint` (#2461) 2 years ago
level_test.go fix(log): toString float32 precision loss and convert uint use `FormatUint` (#2461) 2 years ago
log.go fix: logging middle don't get trace_id value when logger is filterLogger (#2869) 1 year ago
log_test.go fix: rectification of non-standard lint codes (#2746) 2 years ago
std.go fix with logger (#2062) 3 years ago
std_test.go fix: rectification of non-standard lint codes (#2746) 2 years ago
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) 2 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

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