kiel barry 09d44247f7 log: fixes for golint warnings (#16775) | il y a 6 ans | |
---|---|---|
.. | ||
term | il y a 7 ans | |
CONTRIBUTORS | il y a 7 ans | |
LICENSE | il y a 7 ans | |
README.md | il y a 6 ans | |
README_ETHEREUM.md | il y a 7 ans | |
doc.go | il y a 6 ans | |
format.go | il y a 6 ans | |
handler.go | il y a 6 ans | |
handler_glog.go | il y a 7 ans | |
handler_go13.go | il y a 7 ans | |
handler_go14.go | il y a 7 ans | |
logger.go | il y a 6 ans | |
root.go | il y a 7 ans | |
syslog.go | il y a 7 ans |
Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's io
and net/http
packages and is an alternative to the standard library's log
package.
The API of the master branch of log15 should always be considered unstable. If you want to rely on a stable API, you must vendor the library.
import log "github.com/inconshreveable/log15"
// all loggers can have key/value context
srvlog := log.New("module", "app/server")
// all log messages can have key/value context
srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate)
// child loggers with inherited context
connlog := srvlog.New("raddr", c.RemoteAddr())
connlog.Info("connection open")
// lazy evaluation
connlog.Debug("ping remote", "latency", log.Lazy{pingRemote})
// flexible configuration
srvlog.SetHandler(log.MultiHandler(
log.StreamHandler(os.Stderr, log.LogfmtFormat()),
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler("errors.json", log.JSONFormat()))))
Will result in output that looks like this:
WARN[06-17|21:58:10] abnormal conn rate module=app/server rate=0.500 low=0.100 high=0.800
INFO[06-17|21:58:10] connection open module=app/server raddr=10.0.0.1
The following commits broke API stability. This reference is intended to help you understand the consequences of updating to a newer version of log15.
57a084d014
- Added a Get()
method to the Logger
interface to retrieve the current handler93404652ee
- Record
field Call
changed to stack.Call
with switch to github.com/go-stack/stack
a5e7613673
- Restored syslog.Priority
argument to the SyslogXxx
handler constructorsYes. Use log.Ctx
:
srvlog := log.New(log.Ctx{"module": "app/server"})
srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate})
Apache