Warning - incompatible changes.
This fork changes the excellent apex/log
framework in a way that makes it NOT backward compatible with upstream:
Fields
is now a slice rather than a map: fields are no more reordered when logging occurs.- Add a
Trace
level for super detailed logging: the originalTrace
function has been renamed toWatch
.
Other changes:
- use
sync.Pool
for entries and field instances whenever possible. - logging functions now have an optional
kv ...interface{}
vararg parameter expected to be key/value pairs each added as a log field. Values of typeerror
can be passed alone and are automatically assigned to a key 'error'.
Package log implements a simple structured logging API inspired by Logrus, designed with centralization in mind. Read more on Medium.
- apexlogs – handler for Apex Logs
- cli – human-friendly CLI output
- discard – discards all logs
- es – Elasticsearch handler
- graylog – Graylog handler
- json – JSON output handler
- kinesis – AWS Kinesis handler
- level – level filter handler
- logfmt – logfmt plain-text formatter
- memory – in-memory handler for tests
- multi – fan-out to multiple handlers
- papertrail – Papertrail handler
- text – human-friendly colored output
- delta – outputs the delta between log calls and spinner
Example using the Apex Logs handler.
package main
import (
"errors"
"time"
"github.com/eluv-io/apexlog-go"
)
func main() {
ctx := log.WithFields(log.Fields{
{Name: "file", Value: "something.png"},
{Name: "type", Value: "image/png"},
{Name: "user", Value: "tobi"},
})
for range time.Tick(time.Millisecond * 200) {
ctx.Info("upload")
ctx.Info("upload complete")
ctx.Warn("upload retry")
ctx.WithError(errors.New("unauthorized")).Error("upload failed")
ctx.Errorf("failed to upload %s", "img.png")
}
}