Skip to content

eluv-io/apexlog-go

 
 

Repository files navigation

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 original Trace function has been renamed to Watch.

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 type error can be passed alone and are automatically assigned to a key 'error'.

Structured logging for golang

Package log implements a simple structured logging API inspired by Logrus, designed with centralization in mind. Read more on Medium.

Handlers

  • 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

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")
	}
}

Build Status GoDoc

About

Structured logging package for Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.9%
  • Makefile 0.1%