kiel barry 09d44247f7 log: fixes for golint warnings (#16775) %!s(int64=6) %!d(string=hai) anos
..
term ec7f81f4bc log, vendor: vendor in log15 inline into our codebase %!s(int64=7) %!d(string=hai) anos
CONTRIBUTORS ec7f81f4bc log, vendor: vendor in log15 inline into our codebase %!s(int64=7) %!d(string=hai) anos
LICENSE ec7f81f4bc log, vendor: vendor in log15 inline into our codebase %!s(int64=7) %!d(string=hai) anos
README.md 09d44247f7 log: fixes for golint warnings (#16775) %!s(int64=6) %!d(string=hai) anos
README_ETHEREUM.md b9d48b4a93 log: add support for trace level, exit on critical %!s(int64=7) %!d(string=hai) anos
doc.go 09d44247f7 log: fixes for golint warnings (#16775) %!s(int64=6) %!d(string=hai) anos
format.go 09d44247f7 log: fixes for golint warnings (#16775) %!s(int64=6) %!d(string=hai) anos
handler.go 09d44247f7 log: fixes for golint warnings (#16775) %!s(int64=6) %!d(string=hai) anos
handler_glog.go 47af53f9aa log: implement a glog style pattern matching handler %!s(int64=7) %!d(string=hai) anos
handler_go13.go ec7f81f4bc log, vendor: vendor in log15 inline into our codebase %!s(int64=7) %!d(string=hai) anos
handler_go14.go ec7f81f4bc log, vendor: vendor in log15 inline into our codebase %!s(int64=7) %!d(string=hai) anos
logger.go 09d44247f7 log: fixes for golint warnings (#16775) %!s(int64=6) %!d(string=hai) anos
root.go 43362ab4fb log: disable logs by default %!s(int64=7) %!d(string=hai) anos
syslog.go b9d48b4a93 log: add support for trace level, exit on critical %!s(int64=7) %!d(string=hai) anos

README.md

obligatory xkcd

log15 godoc reference Build Status

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.

  • 57a084d014 - Added a Get() method to the Logger interface to retrieve the current handler
  • 93404652ee - Record field Call changed to stack.Call with switch to github.com/go-stack/stack
  • a5e7613673 - Restored syslog.Priority argument to the SyslogXxx 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