gol is a high performance async log kit for golang
gol is a high performance async log infrastructure for golang, which include several useful log backend adapters, include file/file rotate/stmp/slack/elasticsearch etc...
gol support various log levels, you can set the logger's level to disable some lower level output
const (
ALL LogLevel = iota
DEBUG
INFO
WARN
ERROR
CRITICAL
)
gol has several built in adapters
You can create any backend adapter which implement the Adapter interface.
Actually Adapter is a alias of io.Writer
type Adapter interface {
io.WriteCloser
}
gol also include a colorful output
import (
"github.com/philchia/gol"
"runtime"
)
defer gol.Flush()
gol.Debug("Hello, gol!!!")
gol.Criticalf("Hello from %s", runtime.GOOS)
import (
"github.com/philchia/gol"
"runtime"
)
gol.RemoveAdapter(gol.CONSOLELOGGER)
import (
"github.com/philchia/gol"
"runtime"
)
defer gol.Flush()
gol.AddLogAdapter("file", file.NewAdapter("/var/log/tmp.log"))
gol.Debug("Hello, gol!!!")
gol.Criticalf("Hello from %s", runtime.GOOS)
import (
"github.com/philchia/gol"
"runtime"
)
defer gol.Flush()
gol.AddLogAdapter("rotate file", rotatefile.NewAdapter("./temp.log", 6, rotatefile.KB*1))
gol.Debug("Hello, gol!!!")
gol.Criticalf("Hello from %s", runtime.GOOS)
import (
"github.com/philchia/gol"
"runtime"
)
defer gol.Flush()
gol.SetLevel(gol.ERROR)
gol.Debug("Hello, gol!!!") // this will not print
gol.Criticalf("Hello from %s", runtime.GOOS)
import (
"github.com/philchia/gol"
"runtime"
)
defer gol.Flush()
gol.SetOption(gol.Llongfile | gol.Ldate | gol.Ltime | gol.Lmicroseconds)
gol.Debug("Hello, gol!!!")
gol.Criticalf("Hello from %s", runtime.GOOS)
You can implement you own custom adapters which implement the Adapter interface.
import (
"github.com/philchia/gol"
"runtime"
)
defer gol.Flush()
gol.SetOption(gol.Llongfile | gol.Ldate | gol.Ltime | gol.Lmicroseconds)
gol.AddLogAdapter("anonymous", a)
gol.Debug("Hello, gol!!!")
gol.Criticalf("Hello from %s", runtime.GOOS)
$go get github.com/philchia/gol
or you can use go get -u
to update the package
For docs, see Documentation or run:
$godoc github.com/philchia/gol
gol include a benchmark against the builtin log package, run $go test ./... -bench . -benchmem
in your terminal to run the bench
gol code is published under the MIT license