.. | ||
.gitignore | ||
.travis.yml | ||
go.mod | ||
go.sum | ||
interface.go | ||
LICENSE | ||
logger.go | ||
README.md |
lgr - simple logger with some extras
install
go get github/go-pkgz/lgr
usage
l := lgr.New(lgr.Debug, lgr.Caller) // allow debug and caller info
l.Logf("INFO some important err message, %v", err)
l.Logf("DEBUG some less important err message, %v", err)
output looks like this:
2018/01/07 13:02:34.000 INFO {svc/handler.go:101 h.MyFunc1} some important err message, can't open file`
2018/01/07 13:02:34.015 DEBUG {svc/handler.go:155 h.MyFunc2} some less important err message, file is too small`
Without lgr.Caller
it will drop {caller}
part
details
interfaces and default loggers
lgr
package provides a single interfacelgr.L
with a single methodLogf(format string, args ...interface{})
. Function wrapperlgr.Func
allows to makelgr.L
from a function directly.- Default logger functionality can be used without
lgr.New
, but justlgr.Printf
- Two predefined loggers available:
lgr.NoOp
(do-nothing logger) andlgr.Std
(passing directly to stdlib log)
options
lgr.New
call accepts functional options:
lgr.Debug
- turn debug mode on. This allows messages with "DEBUG" level (filtered overwise)lgr.Caller
- adds the caller info each messagelgr.Out(io.Writer)
- sets the output writer, defaultos.Stdout
lgr.Err(io.Writer)
- sets the error writer, defaultos.Stderr
levels
lgr.Logf
recognizes prefixes like "INFO" or "[INFO]" as levels. The full list of supported levels - "DEBUG", "INFO", "WARN", "ERROR", "PANIC" and "FATAL"
DEBUG
will be filtered unlesslgr.Debug
option definedINFO
andWARN
don't have any special behavior attachedERROR
sends messages to both out and err writers- "PANIC" and "FATAL" send messages to both out and err writers. In addition sends dump of callers and runtime info to err only, and call
os.Exit(1)
.