log

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultConsoleLevel is the default log level for the console.
	DefaultConsoleLevel = "crit"
	// DefaultFileLevel is the defaul log level for files.
	DefaultFileLevel = "debug"
	// DefaultFileSizeMiB is the default rotation size in MiB.
	DefaultFileSizeMiB = 50
	// DefaultFileMaxAgeDays is the default rollover age in days.
	DefaultFileMaxAgeDays = 7
	// DefaultFileMaxBackups is the default maximum amount of file backups.
	DefaultFileMaxBackups = 10
	// DefaultFileFlushSeconds is the default amount of time between flushes.
	DefaultFileFlushSeconds uint = 5
)
View Source
const (
	LevelCrit  = Level(log15.LvlCrit)
	LevelError = Level(log15.LvlError)
	LevelWarn  = Level(log15.LvlWarn)
	LevelInfo  = Level(log15.LvlInfo)
	LevelDebug = Level(log15.LvlDebug)
)

The different log levels

View Source
const (
	LevelTraceStr = "trace"
	// TraceMsgPrefix is prepended to TRACE level logging messages.
	TraceMsgPrefix = "[TRACE] "
)

Variables

This section is empty.

Functions

func Crit

func Crit(msg string, ctx ...interface{})

Crit logs at crit level.

func CtxWith added in v0.4.0

func CtxWith(ctx context.Context, logger Logger) context.Context

CtxWith returns a new context, based on ctx, that embeds argument logger. The logger can be recovered using GetLogger. Attaching a logger to a context which already contains one will overwrite the existing value.

func Debug

func Debug(msg string, ctx ...interface{})

Debug logs at debug level.

func Discard added in v0.5.0

func Discard()

Discard sets the logger up to discard all log entries. This is useful for testing.

func Error

func Error(msg string, ctx ...interface{})

Error logs at error level.

func Flush

func Flush()

Flush writes the logs to the underlying buffer.

func HandlePanic added in v0.5.0

func HandlePanic()

HandlePanic catches panics and logs them.

func Info

func Info(msg string, ctx ...interface{})

Info logs at info level.

func Log added in v0.1.1

func Log(level Level, msg string, ctx ...interface{})

Log logs at the given level.

func Setup added in v0.5.0

func Setup(cfg Config) error

Setup configures the logging library with the given config.

func Trace added in v0.4.0

func Trace(msg string, ctx ...interface{})

Trace logs at trace level

func Warn

func Warn(msg string, ctx ...interface{})

Warn logs at warn level.

Types

type Config added in v0.5.0

type Config struct {
	config.NoValidator
	// File is the configuration for file logging.
	File FileConfig `toml:"file,omitempty"`
	// Console is the configuration for the console logging.
	Console ConsoleConfig `toml:"console,omitempty"`
}

Config is the configuration for the logger.

func (*Config) ConfigName added in v0.5.0

func (c *Config) ConfigName() string

ConfigName returns the name this config should have in a struct embedding this.

func (*Config) InitDefaults added in v0.5.0

func (c *Config) InitDefaults()

InitDefaults populates unset fields in cfg to their default values (if they have one).

func (*Config) Sample added in v0.5.0

func (c *Config) Sample(dst io.Writer, path config.Path, ctx config.CtxMap)

Sample writes the sample configuration to the dst writer.

type ConsoleConfig added in v0.5.0

type ConsoleConfig struct {
	// Level of console logging (defaults to DefaultConsoleLevel).
	Level string `toml:"level,omitempty"`
}

ConsoleConfig is the config for the console logger.

func (*ConsoleConfig) InitDefaults added in v0.5.0

func (c *ConsoleConfig) InitDefaults()

InitDefaults populates unset fields in cfg to their default values (if they have one).

type DebugID added in v0.5.0

type DebugID uint32

DebugID is used to correlate behavior in logs. A DebugID is allocated for each outgoing request/response or notify message exchange, and for each handler executed during ListenAndServe.

func NewDebugID added in v0.5.0

func NewDebugID() DebugID

NewDebugID creates a new debug id.

func (DebugID) String added in v0.5.0

func (id DebugID) String() string

type FileConfig added in v0.5.0

type FileConfig struct {
	// Path is the location of the logging file. If unset, no file logging is
	// performed.
	Path string `toml:"path,omitempty"`
	// Level of file logging (defaults to DefaultFileLevel).
	Level string `toml:"level,omitempty"`
	// Size is the max size of log file in MiB (defaults to DefaultFileSizeMiB).
	Size uint `toml:"size,omitempty"`
	// MaxAge is the max age of log file in days (defaults to
	// DefaultFileMaxAgeDays).
	MaxAge uint `toml:"max_age,omitempty"`
	// MaxBackups is the max number of log files to retain (defaults to
	// DefaultFileMaxBackups).
	MaxBackups uint `toml:"max_backups,omitempty"`
	// FlushInterval specifies how frequently to flush to the log file, in
	// seconds (defaults to DefaultFileFlushSeconds).
	FlushInterval *uint `toml:"flush_interval,omitempty"`
	// Compress can be set to enable rotated file compression.
	Compress bool `toml:"compress,omitempty"`
}

FileConfig is the configuration for the file logger.

func (*FileConfig) InitDefaults added in v0.5.0

func (c *FileConfig) InitDefaults()

InitDefaults populates unset fields in cfg to their default values (if they have one).

type Handler

type Handler interface {
	log15.Handler
}

Handler wraps log15.Handler, should only be used for testing.

type Level added in v0.5.0

type Level log15.Lvl

Level is the log level.

func LevelFromString added in v0.5.0

func LevelFromString(lvl string) (Level, error)

LevelFromString parses the log level.

func (Level) String added in v0.5.0

func (l Level) String() string

type Logger

type Logger interface {
	New(ctx ...interface{}) Logger
	Trace(msg string, ctx ...interface{})
	Debug(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Crit(msg string, ctx ...interface{})
}

Logger describes the logger interface.

func FromCtx added in v0.4.0

func FromCtx(ctx context.Context) Logger

FromCtx returns the logger embedded in ctx if one exists, or the root logger otherwise. FromCtx is guaranteed to never return nil.

func New

func New(ctx ...interface{}) Logger

New creates a logger with the given context.

func Root

func Root() Logger

Root returns the root logger. It's a logger without any context.

type Span added in v0.5.0

type Span struct {
	Logger
	Span opentracing.Span
}

Span is a logger that attaches all logs to the span.

func (Span) Crit added in v0.5.0

func (s Span) Crit(msg string, ctx ...interface{})

Crit logs to the logger and span.

func (Span) Debug added in v0.5.0

func (s Span) Debug(msg string, ctx ...interface{})

Debug logs to the logger and span.

func (Span) Error added in v0.5.0

func (s Span) Error(msg string, ctx ...interface{})

Error logs to the logger and span.

func (Span) Info added in v0.5.0

func (s Span) Info(msg string, ctx ...interface{})

Info logs to the logger and span.

func (Span) Trace added in v0.5.0

func (s Span) Trace(msg string, ctx ...interface{})

Trace logs to the logger and span.

func (Span) Warn added in v0.5.0

func (s Span) Warn(msg string, ctx ...interface{})

Warn logs to the logger and span.

Directories

Path Synopsis
Package mock_log is a generated GoMock package.
Package mock_log is a generated GoMock package.

Jump to

Keyboard shortcuts

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