eventlog

package
v0.0.0-...-e4696f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2014 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LdJSONFormatter = func() {
	logrus.SetFormatter(&PoliteJSONFormatter{})
}

LdJSONFormatter formats the event log as line-delimited JSON

View Source
var LevelDebug = func() {
	logrus.SetLevel(logrus.DebugLevel)
}
View Source
var LevelError = func() {
	logrus.SetLevel(logrus.ErrorLevel)
}
View Source
var LevelInfo = func() {
	logrus.SetLevel(logrus.InfoLevel)
}
View Source
var TextFormatter = func() {
	logrus.SetFormatter(&logrus.TextFormatter{})
}

Functions

func Configure

func Configure(options ...Option)

func ContextWithMetadata

func ContextWithMetadata(ctx context.Context, l Loggable) context.Context

Types

type EventLogger

type EventLogger interface {
	StandardLogger

	// Event merges structured data from the provided inputs into a single
	// machine-readable log event.
	//
	// If the context contains metadata, a copy of this is used as the base
	// metadata accumulator.
	//
	// If one or more loggable objects are provided, these are deep-merged into base blob.
	//
	// Next, the event name is added to the blob under the key "event". If
	// the key "event" already exists, it will be over-written.
	//
	// Finally the timestamp and package name are added to the accumulator and
	// the metadata is logged.
	Event(ctx context.Context, event string, m ...Loggable)
}

EventLogger extends the StandardLogger interface to allow for log items containing structured metadata

func Logger

func Logger(system string) EventLogger

Logger retrieves an event logger by name

type LogRotatorConfig

type LogRotatorConfig struct {
	Filename   string
	MaxSizeMB  uint64
	MaxBackups uint64
	MaxAgeDays uint64
}

type Loggable

type Loggable interface {
	Loggable() map[string]interface{}
}

Loggable describes objects that can be marshalled into Metadata for logging

type Metadata

type Metadata map[string]interface{}

Metadata is a convenience type for generic maps

func DeepMerge

func DeepMerge(b, a Metadata) Metadata

DeepMerge merges the second Metadata parameter into the first. Nested Metadata are merged recursively. Primitives are over-written.

func MetadataFromContext

func MetadataFromContext(ctx context.Context) (Metadata, error)

func Metadatify

func Metadatify(i interface{}) (Metadata, error)

Metadatify converts maps into Metadata

func Uuid

func Uuid(key string) Metadata

Uuid returns a Metadata with the string key and UUID value

func (Metadata) JsonString

func (m Metadata) JsonString() (string, error)

func (Metadata) Loggable

func (m Metadata) Loggable() map[string]interface{}

Loggable implements the Loggable interface

type Option

type Option func()

func Output

func Output(w io.Writer) Option

func OutputRotatingLogFile

func OutputRotatingLogFile(config LogRotatorConfig) Option

type PoliteJSONFormatter

type PoliteJSONFormatter struct{}

PoliteJSONFormatter marshals entries into JSON encoded slices (without overwriting user-provided keys). How polite of it!

func (*PoliteJSONFormatter) Format

func (f *PoliteJSONFormatter) Format(entry *logrus.Entry) ([]byte, error)

type StandardLogger

type StandardLogger interface {
	Critical(args ...interface{})
	Criticalf(format string, args ...interface{})
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Notice(args ...interface{})
	Noticef(format string, args ...interface{})
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})
	Warning(args ...interface{})
	Warningf(format string, args ...interface{})
}

StandardLogger provides API compatibility with standard printf loggers eg. go-logging

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL