具有文件记录功能的可配置记录器

I'm looking for logging library in Go, something similar like log4j in java.

  1. As I understood build-in logger from 'log' package have restricted possibility in configurations and log levels.

  2. Maybe someone used one of https://godoc.org/github.com/op/go-logging, https://github.com/cihub/seelog?

  3. What about concurrency issues? What is the best way to store logger in system? One per program or create loggers every time?

Thanks!

The std lib log package handles a lot of this for you. You can either log to STDOUT/STDERR or set the output of the log package itself by doing as follows:

log.SetOutput(<something that implements io.Writer>)
log.Println("some message")

And depending on what that io.Writer is (i.e. an os.File, net.TCPConn, net.UDPConn, etc) it will log "some message" to it.

This can also be done on a per logger basis like so

logger := log.New(<something that implements io.Writer>, <log prefix string>, <log flags https://golang.org/pkg/log/#pkg-constants>)
logger.Println("Some message")

This example will accomplish the same thing and add a prefix to each log. The second example is a struct instead of functions from the package, so that will have to be shared across Goroutines correrctly. This example can implement log levels by having each level be its own logger instance.

It's also worth taking a look at logrus https://github.com/Sirupsen/logrus it handles a lot of the boilerplate for you.