log

package
v0.0.0-...-cbf2afa Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 10 Imported by: 5

Documentation

Overview

Package log provids a severity-based key/value logging replacement for Go's standard logger.

The output is a simple and clean logging format that strikes the perfect balance between being human readable and easy to write parsing tools for.

Examples:

ERROR | MyLibrary | Could not connect to server. | url='http://timehop.com/' error='timed out'
INFO  | MyLibrary | Something happened.

Index

Constants

View Source
const (
	FlagsNone          = 0
	FlagsDate          = log.Ldate
	FlagsTime          = log.Ltime
	FlagsPrecisionTime = log.Lmicroseconds
	FlagsLongFile      = log.Llongfile
	FlagsShortFile     = log.Lshortfile
	FlagsDefault       = log.LstdFlags
)

Variables

This section is empty.

Functions

func Debug

func Debug(id, description string, keysAndValues ...interface{})

Debug outputs an info message with an optional list of key/value pairs.

If LogLevel is set below LevelDebug, calling this method will yield no side effects.

func Error

func Error(id, description string, keysAndValues ...interface{})

Error outputs an error message with an optional list of key/value pairs.

func Fatal

func Fatal(id, description string, keysAndValues ...interface{})

Fatal outputs a severe error message just before terminating the process. Use judiciously.

func Info

func Info(id, description string, keysAndValues ...interface{})

Info outputs an info message with an optional list of key/value pairs.

If LogLevel is set below LevelInfo, calling this method will yield no side effects.

func SetLevel

func SetLevel(level LogLevel)

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the default logger.

All new logger instances created after this call will use the provided io.Writer as destination for their output.

If you specifically want to change the output of DefaultLogger and not affect new Logger instance creation, use log.DefaultLogger.SetOutput()

func SetPrefix

func SetPrefix(prefix string)

Changes the global prefix for all log statements.

New logger instances created after this method is called will be affected. Prefix is useful for multi-tail scenarios (tailing logs across multiple machines, to help distinguish which is which.)

func SetStackTrace

func SetStackTrace(trace bool)

func SetTimestampFlags

func SetTimestampFlags(flags int)

SetFlags changes the timestamp flags on the output of the default logger.

func Trace

func Trace(id, description string, keysAndValues ...interface{})

Trace outputs an info message with an optional list of key/value pairs.

If LogLevel is set below LevelTrace, calling this method will yield no side effects.

func Warn

func Warn(id, description string, keysAndValues ...interface{})

Warn outputs a warning message with an optional list of key/value pairs.

If LogLevel is set below LevelWarn, calling this method will yield no side effects.

Types

type Config

type Config struct {
	Format LogFormat
	ID     string
}

Logger config. Default/unset values for each attribute are safe.

type LogFormat

type LogFormat string
const (
	DefaultFormat   LogFormat = "" // Use env variable, defaulting to PlainTextFormat
	PlainTextFormat LogFormat = "text"
	JsonFormat      LogFormat = "json"
	KeyValueFormat  LogFormat = "key_value"
)

func SanitizeFormat

func SanitizeFormat(format LogFormat) LogFormat

type LogLevel

type LogLevel int
const (
	LevelFatal LogLevel = iota
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
	LevelTrace
)

type LogLevelName

type LogLevelName string
const (
	LevelFatalName LogLevelName = "FATAL"
	LevelErrorName LogLevelName = "ERROR"
	LevelWarnName  LogLevelName = "WARN"
	LevelInfoName  LogLevelName = "INFO"
	LevelDebugName LogLevelName = "DEBUG"
	LevelTraceName LogLevelName = "TRACE"
)

type Logger

type Logger interface {
	Fatal(description string, keysAndValues ...interface{})
	Error(description string, keysAndValues ...interface{})
	Warn(description string, keysAndValues ...interface{})
	Info(description string, keysAndValues ...interface{})
	Debug(description string, keysAndValues ...interface{})
	Trace(description string, keysAndValues ...interface{})

	SetLevel(level LogLevel)
	SetOutput(w io.Writer)
	SetTimestampFlags(flags int)
	SetStaticField(name string, value interface{})
	SetStackTrace(trace bool)
}
var (
	DefaultLogger Logger
)

func New

func New(conf Config, staticKeysAndValues ...interface{}) Logger

New creates a new logger instance.

func NewDefault

func NewDefault() Logger

Jump to

Keyboard shortcuts

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