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
- Console adapter support write log to stderr, and this is the default adapter
- File adapter support write log to file
- File rotate adapter support write log to rotate files
- Smtp adapter support write log to email
- Slack adapter support write log to given slack channel
- ES adapter support write log to elastic search (under development)
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
- Log level support
- Customizable log option support
- Async write
- Colorful output
- Flush buffered log
- Toggle console adapter
- Logrotate
- Mail adapter
- Slack adapter
- Level support for single adapter
- Elastic Search adapter for ELK stack
- 100% coverage
- Customizable msg buffer size
gol code is published under the MIT license