log

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: Apache-2.0 Imports: 5 Imported by: 9

Documentation

Overview

Package log implements a logging package.

Index

Constants

This section is empty.

Variables

View Source
var SimpleLogger = NewLogger(os.Stdout)

SimpleLogger prints logging information to standard out.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	File   string                 `json:"file" yaml:"file"`
	Level  string                 `json:"level" yaml:"level"`
	Fields map[string]interface{} `json:"fields" yaml:"fields"`
}

Configuration defines configuration for logging.

func (Configuration) BuildLogger

func (cfg Configuration) BuildLogger() (Logger, error)

BuildLogger builds a new Logger based on the configuration.

type Field

type Field interface {
	Key() string
	Value() interface{}
}

Field is a single field of additional information passed to the logger.

func NewErrField

func NewErrField(err error) Field

NewErrField wraps an error string as a Field named "error".

func NewField

func NewField(key string, value interface{}) Field

NewField creates a new log field.

type Fields

type Fields []Field

Fields is a list of log fields that implements the LoggerFields interface.

func (Fields) Len

func (f Fields) Len() int

Len returns the length.

func (Fields) ValueAt

func (f Fields) ValueAt(i int) Field

ValueAt returns a value for an index.

type Level

type Level int

Level is the level of logging used by LevelLogger.

const (
	LevelAll Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

The minimum level that will be logged. e.g. LevelError only logs errors and fatals.

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel parses a log level string to log level.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	// Enabled returns whether the given level is enabled.
	Enabled(level Level) bool

	// Fatalf logs a message, then exits with os.Exit(1).
	Fatalf(msg string, args ...interface{})

	// Fatal logs a message, then exits with os.Exit(1).
	Fatal(msg string)

	// Errorf logs a message at error priority.
	Errorf(msg string, args ...interface{})

	// Error logs a message at error priority.
	Error(msg string)

	// Warnf logs a message at warning priority.
	Warnf(msg string, args ...interface{})

	// Warn logs a message at warning priority.
	Warn(msg string)

	// Infof logs a message at info priority.
	Infof(msg string, args ...interface{})

	// Info logs a message at info priority.
	Info(msg string)

	// Debugf logs a message at debug priority.
	Debugf(msg string, args ...interface{})

	// Debug logs a message at debug priority.
	Debug(msg string)

	// Fields returns the fields that this logger contains.
	Fields() LoggerFields

	// WithFields returns a logger with the current logger's fields and fields.
	WithFields(fields ...Field) Logger
}

Logger provides an abstract interface for logging.

var NullLogger Logger = nullLogger{}

NullLogger is a logger that emits nowhere.

func NewLevelLogger

func NewLevelLogger(logger Logger, level Level) Logger

NewLevelLogger returns a logger that only logs messages with a minimum of level.

func NewLogger

func NewLogger(writer io.Writer, fields ...Field) Logger

NewLogger returns a Logger that writes to the given writer.

type LoggerFields

type LoggerFields interface {
	// Len returns the length
	Len() int

	// ValueAt returns a value for an index.
	ValueAt(i int) Field
}

LoggerFields is a list of Fields used to pass additional information to the logger.

Jump to

Keyboard shortcuts

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