Umputun b1dc239277 switch logging to lgr | 5 лет назад | |
---|---|---|
.. | ||
.gitignore | 5 лет назад | |
.travis.yml | 5 лет назад | |
LICENSE | 5 лет назад | |
README.md | 5 лет назад | |
go.mod | 5 лет назад | |
go.sum | 5 лет назад | |
interface.go | 5 лет назад | |
interface_test.go | 5 лет назад | |
logger.go | 5 лет назад | |
logger_test.go | 5 лет назад |
go get github/go-pkgz/lgr
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
lgr
package provides a single interface lgr.L
with a single method Logf(format string, args ...interface{})
. Function wrapper lgr.Func
allows to make lgr.L
from a function directly.lgr.New
, but just lgr.Printf
lgr.NoOp
(do-nothing logger) and lgr.Std
(passing directly to stdlib log)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, default os.Stdout
lgr.Err(io.Writer)
- sets the error writer, default os.Stderr
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 unless lgr.Debug
option definedINFO
and WARN
don't have any special behavior attachedERROR
sends messages to both out and err writersos.Exit(1)
.