Categorygithub.com/apex/log
modulepackage
1.9.0
Repository: https://github.com/apex/log.git
Documentation: pkg.go.dev

# README

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

func main() {
	ctx := log.WithFields(log.Fields{
		"file": "something.png",
		"type": "image/png",
		"user": "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

# Packages

# Functions

Debug level message.
Debugf level formatted message.
Error level message.
Errorf level formatted message.
Fatal level message, followed by an exit.
Fatalf level formatted message, followed by an exit.
FromContext returns the logger from context, or log.Log.
Info level message.
Infof level formatted message.
MustParseLevel parses level string or panics.
NewContext returns a new context with logger.
NewEntry returns a new entry for `log`.
ParseLevel parses level string.
SetHandler sets the handler.
SetLevel sets the log level.
SetLevelFromString sets the log level from a string, panicing when invalid.
Trace returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.
Warn level message.
Warnf level formatted message.
WithDuration returns a new entry with the "duration" field set to the given duration in milliseconds.
WithError returns a new entry with the "error" set to `err`.
WithField returns a new entry with the `key` and `value` set.
WithFields returns a new entry with `fields` set.

# Constants

Log levels.
Log levels.
Log levels.
Log levels.
Log levels.
Log levels.

# Variables

ErrInvalidLevel is returned if the severity level is invalid.
singletons ftw?.
Now returns the current time.

# Structs

Entry
Entry represents a single log entry.
Logger represents a logger with configurable Level and Handler.

# Interfaces

Fielder is an interface for providing fields to custom types.
Handler is used to handle log events, outputting them to stdio or sending them to remote services.
Interface represents the API of both Logger and Entry.

# Type aliases

Fields represents a map of entry level data used for structured logging.
The HandlerFunc type is an adapter to allow the use of ordinary functions as log handlers.
Level of severity.