repositorypackage
0.0.0-20210327090009-d60bf476a16a
Repository: https://github.com/mehdioa/nlog.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
nlog
Node Logger, fast and thread-safe logger for Golang
Node Logger is a KISS (Keep It Simple, Stupid) logger that
suits most people. It is much faster than Logrus and Log15, and
asymtotically as fast as Logxi.
The motivation for writing this logger is that none of the other loggers seems to be thread-safe and even they are buggy. I sacrificed fancy features in favour of performance and safety.
Please feel free to suggest features and pull requests.
Install
go get github.com/mehdioa/nlog
Example
package main
import "github.com/mehdioa/nlog"
var log *nlog.Logger
func main() {
formatter := nlog.NewTextFormatter(true, true)
log = nlog.NewLogger(nlog.DebugLevel, formatter)
log.Debugf("Logging without a node is possible")
sNode := log.New("Server", nlog.Data{"Protocol": "tcp", "Port": 12542})
sNode.Debugf("Server is serving")
cNode := sNode.NewNode("Client", nlog.Data{"RemoteAddr": "[::1]9183", "error": nil})
cNode.Infof("Client is serving")
}
Formatters
The built-in logging formatters are:
nlog.NewTextFormatter(show_caller, enable_color bool)
.nlog.NewJsonFormatter(show_caller bool)
. Logs fields as JSON.
Use NLog in your library
The best way to use nlog in your library is to define
package customPackage
import "github.com/mehdioa/nlog"
var log *nlog.Logger
func SetLogger(logger *nlog.Logger) {
log = logger
}
and then use this log in your library. Just remember to initialize a Logger in your application and call
package main
import "customPackage"
var logger *nlog.Logger
func main() {
formatter := nlog.NewTextFormatter(true, true)
log = nlog.NewLogger(nlog.DebugLevel, formatter)
customPackage.SetLogger(log)
}