b628d72766
This changes the CI / release builds to use the latest Go version. It also upgrades golangci-lint to a newer version compatible with Go 1.19. In Go 1.19, godoc has gained official support for links and lists. The syntax for code blocks in doc comments has changed and now requires a leading tab character. gofmt adapts comments to the new syntax automatically, so there are a lot of comment re-formatting changes in this PR. We need to apply the new format in order to pass the CI lint stage with Go 1.19. With the linter upgrade, I have decided to disable 'gosec' - it produces too many false-positive warnings. The 'deadcode' and 'varcheck' linters have also been removed because golangci-lint warns about them being unmaintained. 'unused' provides similar coverage and we already have it enabled, so we don't lose much with this change. |
||
---|---|---|
.. | ||
CONTRIBUTORS | ||
LICENSE | ||
README.md | ||
README_ETHEREUM.md | ||
doc.go | ||
format.go | ||
format_test.go | ||
handler.go | ||
handler_glog.go | ||
handler_go13.go | ||
handler_go14.go | ||
logger.go | ||
root.go | ||
syslog.go |
README.md
log15
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.
Features
- A simple, easy-to-understand API
- Promotes structured logging by encouraging use of key/value pairs
- Child loggers which inherit and add their own private context
- Lazy evaluation of expensive operations
- Simple Handler interface allowing for construction of flexible, custom logging configurations with a tiny API.
- Color terminal support
- Built-in support for logging to files, streams, syslog, and the network
- Support for forking records to multiple handlers, buffering records for output, failing over from failed handler writes, + more
Versioning
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.
Importing
import log "github.com/inconshreveable/log15"
Examples
// 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
Breaking API Changes
The following commits broke API stability. This reference is intended to help you understand the consequences of updating to a newer version of log15.
- 57a084d014d4150152b19e4e531399a7145d1540 - Added a
Get()
method to theLogger
interface to retrieve the current handler - 93404652ee366648fa622b64d1e2b67d75a3094a -
Record
fieldCall
changed tostack.Call
with switch togithub.com/go-stack/stack
- a5e7613673c73281f58e15a87d2cf0cf111e8152 - Restored
syslog.Priority
argument to theSyslogXxx
handler constructors
FAQ
The varargs style is brittle and error prone! Can I have type safety please?
Yes. Use log.Ctx
:
srvlog := log.New(log.Ctx{"module": "app/server"})
srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate})
License
Apache