An easy-to-use logging libraty in Go, modeled after Java's Slf4j.
The code is copyright (c) 2022 AlertAvert.com. All rights reserved
The code is released under the Apache 2.0 License, see LICENSE
for details.
This is a simple logging package, resembling the functionality that is available in typical Java logging libraries (such as Log4j).
For an example usage see example.go
.
Getting a logger
:
var log = logging.NewLog("can.be/anything")
the name of the logger will be emitted at each log line, along with the logging level and the source file and line no. of where the logging happened:
2022/06/03 22:48:35 example.go:17: example[INFO] An INFO message
Depending on the logging.LogLevel
for the Log
, some logs will be emitted, and other may not:
log.Level = logging.INFO
log.Info("An INFO message")
log.Debug("This will NOT be logged")
The default level is INFO
.
There are a couple of "special" convenience logs: a RootLog
that can be used to quickly log when no special settings are needed, and a NullLog
which "logs to nowhere" (technically, to /dev/null
) which can be useful when injected, for example, during tests, where logs would pollute the tests' output.
Use the package in your program by importing it:
import "github.com/massenz/slf4go/logging"
The example
script can be run with:
$ go build -o bin/log-sample example.go
$ bin/log-sample -trace
Contributions are welcome, and can be submitted via pull requests.
Please make sure to run go fmt
on your code before submitting.