Documentation
¶
Index ¶
- Constants
- func Crit(msg string, ctx ...interface{})
- func CtxWith(ctx context.Context, logger Logger) context.Context
- func Debug(msg string, ctx ...interface{})
- func Discard()
- func Error(msg string, ctx ...interface{})
- func Flush()
- func HandlePanic()
- func Info(msg string, ctx ...interface{})
- func Log(level Level, msg string, ctx ...interface{})
- func Setup(cfg Config) error
- func Trace(msg string, ctx ...interface{})
- func Warn(msg string, ctx ...interface{})
- type Config
- type ConsoleConfig
- type DebugID
- type FileConfig
- type Handler
- type Level
- type Logger
- type Span
- func (s Span) Crit(msg string, ctx ...interface{})
- func (s Span) Debug(msg string, ctx ...interface{})
- func (s Span) Error(msg string, ctx ...interface{})
- func (s Span) Info(msg string, ctx ...interface{})
- func (s Span) Trace(msg string, ctx ...interface{})
- func (s Span) Warn(msg string, ctx ...interface{})
Constants ¶
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 )
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
const ( LevelTraceStr = "trace" // TraceMsgPrefix is prepended to TRACE level logging messages. TraceMsgPrefix = "[TRACE] " )
Variables ¶
This section is empty.
Functions ¶
func CtxWith ¶ added in v0.4.0
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 Discard ¶ added in v0.5.0
func Discard()
Discard sets the logger up to discard all log entries. This is useful for testing.
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
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).
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.
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 Level ¶ added in v0.5.0
Level is the log level.
func LevelFromString ¶ added in v0.5.0
LevelFromString parses the log level.
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.
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.