update log/readme.md (#1085)

* update log/readme.md

Co-authored-by: chenzhihui <zhihui_chen@foxmail.com>
pull/1090/head
包子 3 years ago committed by GitHub
parent a928622f27
commit b4dd478bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      log/README.md

@ -1,27 +1,36 @@
# Log
# Logger
## Usage
### Structured logging
```go
var logger log.Logger = log.MultiLogger(log.NewStdLogger(os.Stdout), syslog.NewLogger())
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")
var helper log.Helper = log.NewHelper(logger)
// 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")
```

Loading…
Cancel
Save