Categorygithub.com/eluv-io/apexlog-go
modulepackage
1.9.1-elv4
Repository: https://github.com/eluv-io/apexlog-go.git
Documentation: pkg.go.dev

# README

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

# Packages

No description provided by the author

# 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.
No description provided by the author
ParseLevel parses level string.
SetHandler sets the handler.
SetLevel sets the log level.
SetLevelFromString sets the log level from a string, panicing when invalid.
Warn level message.
Warnf level formatted message.
Watch returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.
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.
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.
No description provided by the author
Logger represents a logger with configurable Level and Handler.

# Interfaces

Asynchronous is an optional interface for handlers that wish to keep log entries (known implementation are in multi, es, memory).
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 and exposes 3 types of functions: - functions named like WithXX and Watch return entries that can be used in chained call - xxf are in printf style with message format and arguments - logging functions - like Info - log a message and optional kv arguments that are expected to be key/value pairs exception made of error values that can be passed alone and will automatically be assigned to a key 'error'.
Sanitizer is an interface for types that may contain sensitive information (like passwords), which shouldn't be printed to the log.

# Type aliases

Fields represents a slice 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.