istanbul-tools/vendor/github.com/inconshreveable/log15
Alan Chen f00e1c3053 glide, vendor: add log15 2017-09-12 12:16:48 +08:00
..
ext glide, vendor: add log15 2017-09-12 12:16:48 +08:00
stack glide, vendor: add log15 2017-09-12 12:16:48 +08:00
term glide, vendor: add log15 2017-09-12 12:16:48 +08:00
.travis.yml glide, vendor: add log15 2017-09-12 12:16:48 +08:00
CONTRIBUTORS glide, vendor: add log15 2017-09-12 12:16:48 +08:00
LICENSE glide, vendor: add log15 2017-09-12 12:16:48 +08:00
README.md glide, vendor: add log15 2017-09-12 12:16:48 +08:00
RELEASING.md glide, vendor: add log15 2017-09-12 12:16:48 +08:00
bench_test.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
doc.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
format.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
handler.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
handler_appengine.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
handler_other.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
log15_test.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
logger.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
root.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00
syslog.go glide, vendor: add log15 2017-09-12 12:16:48 +08:00

README.md

obligatory xkcd

log15 godoc reference

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. Using a stable version of the log15 package is supported by gopkg.in. Include your dependency like so:

import log "gopkg.in/inconshreveable/log15.v2"

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.JsonHandler())))

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