Skip to content

Repository files navigation

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/apex/log"
)
funcmain() {
ctx:=log.WithFields(log.Fields{
"file": "something.png",
"type": "image/png",
"user": "tobi",
})
forrangetime.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 StatusGoDoc

About

Structured logging package for Go.

Topics

Resources

Stars

1.4k stars

Watchers

32 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages