Documentation ¶
Overview ¶
Package logur is an opinionated collection of logging best practices.
Check the readme for detailed documentation: https://github.com/goph/logur/blob/master/README.md
Also, check the example package for detailed examples: https://godoc.org/github.com/goph/logur/examples
Index ¶
- func LogEventsEqual(expected LogEvent, actual LogEvent) error
- func NewErrorStandardLogger(logger Logger, prefix string, flag int) *log.Logger
- func NewLevelWriter(logger Logger, level Level) *io.PipeWriter
- func NewStandardLogger(logger Logger, level Level, prefix string, flag int) *log.Logger
- func NewWriter(logger Logger) *io.PipeWriter
- type Fields
- type Level
- type LevelEnabler
- type LogEvent
- type LogFunc
- type Logger
- type MessageLogger
- type PrintLogger
- type TestLogger
- func (l *TestLogger) Count() int
- func (l *TestLogger) Debug(msg string, fields ...map[string]interface{})
- func (l *TestLogger) Error(msg string, fields ...map[string]interface{})
- func (l *TestLogger) Events() []LogEvent
- func (l *TestLogger) Info(msg string, fields ...map[string]interface{})
- func (l *TestLogger) LastEvent() *LogEvent
- func (l *TestLogger) Trace(msg string, fields ...map[string]interface{})
- func (l *TestLogger) Warn(msg string, fields ...map[string]interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogEventsEqual ¶ added in v0.8.0
LogEventsEqual asserts that two LogEvents are identical and returns an error with detailed information if not.
func NewErrorStandardLogger ¶ added in v0.8.0
NewErrorStandardLogger returns a new standard library logger for error level logging (eg. for HTTP servers).
func NewLevelWriter ¶
func NewLevelWriter(logger Logger, level Level) *io.PipeWriter
NewLevelWriter creates a new writer from a Logger for a specific level of log events.
func NewStandardLogger ¶
NewStandardLogger returns a new standard library logger.
func NewWriter ¶
func NewWriter(logger Logger) *io.PipeWriter
NewWriter creates a new writer from a Logger with a default Info level.
Types ¶
type Fields ¶
type Fields map[string]interface{}
Fields is used to define structured fields which are appended to log events. It can be used as a shorthand for map[string]interface{}.
type Level ¶
type Level uint32
Level represents the same levels as defined in Logger.
const ( // Even more fine-grained information than Debug events. // Loggers not supporting this level should fall back to Debug. Trace Level = iota // A verbose series of information events. // They are useful when debugging the system. Debug // General information about what's happening inside the system. Info // Non-critical events that should be looked at. Warn // Critical events that require immediate attention. Error )
Levels as defined in Logger.
func ParseLevel ¶
ParseLevel takes a string level and returns the defined log level constant. If the level is not defined, it returns false as the second parameter.
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type LevelEnabler ¶ added in v0.6.0
type LevelEnabler interface { // LevelEnabled checks if a level is enabled in a logger. LevelEnabled(level Level) bool }
LevelEnabler checks if a level is enabled in a logger. If the logger cannot reliably decide the correct level this method MUST return true.
type Logger ¶
type Logger interface { // Trace logs a Trace event. // // Even more fine-grained information than Debug events. // Loggers not supporting this level should fall back to Debug. Trace(msg string, fields ...map[string]interface{}) // Debug logs a Debug event. // // A verbose series of information events. // They are useful when debugging the system. Debug(msg string, fields ...map[string]interface{}) // Info logs an Info event. // // General information about what's happening inside the system. Info(msg string, fields ...map[string]interface{}) // Warn logs a Warn(ing) event. // // Non-critical events that should be looked at. Warn(msg string, fields ...map[string]interface{}) // Error logs an Error event. // // Critical events that require immediate attention. // Loggers commonly provide Fatal and Panic levels above Error level, // but exiting and panicing is out of scope for a logging library. Error(msg string, fields ...map[string]interface{}) }
Logger is a unified interface for various logging use cases and practices, including:
- leveled logging
- leveled formatters
- structured logging
func NewNoopLogger ¶ added in v0.7.0
func NewNoopLogger() Logger
NewNoopLogger creates a no-op logger that discards all received log events. Useful in examples and as a fallback logger.
func WithFields ¶ added in v0.6.0
WithFields returns a new logger instance that attaches the given fields to every subsequent log call.
type MessageLogger ¶ added in v0.7.1
type MessageLogger struct {
// contains filtered or unexported fields
}
MessageLogger simplifies the Logger interface by removing the second context parameter. Useful when there is no need for contextual logging.
func NewMessageLogger ¶ added in v0.7.1
func NewMessageLogger(logger Logger) *MessageLogger
NewMessageLogger returns a new MessageLogger instance.
func (*MessageLogger) Debug ¶ added in v0.7.1
func (l *MessageLogger) Debug(msg string)
Debug logs a Debug level event.
func (*MessageLogger) Error ¶ added in v0.7.1
func (l *MessageLogger) Error(msg string)
Error logs a Error level event.
func (*MessageLogger) Info ¶ added in v0.7.1
func (l *MessageLogger) Info(msg string)
Info logs a Info level event.
func (*MessageLogger) Trace ¶ added in v0.7.1
func (l *MessageLogger) Trace(msg string)
Trace logs a Trace level event.
func (*MessageLogger) Warn ¶ added in v0.7.1
func (l *MessageLogger) Warn(msg string)
Warn logs a Warn level event.
type PrintLogger ¶ added in v0.8.0
type PrintLogger struct {
// contains filtered or unexported fields
}
PrintLogger logs messages with fmt.Print* function semantics.
func NewErrorPrintLogger ¶ added in v0.8.0
func NewErrorPrintLogger(logger Logger) *PrintLogger
NewErrorPrintLogger returns a new PrintLogger that logs everything on error level.
func NewPrintLogger ¶ added in v0.8.0
func NewPrintLogger(logger LogFunc) *PrintLogger
NewPrintLogger returns a new PrintLogger.
func (*PrintLogger) Print ¶ added in v0.8.0
func (l *PrintLogger) Print(v ...interface{})
Print logs a line with fmt.Print semantics.
func (*PrintLogger) Printf ¶ added in v0.8.0
func (l *PrintLogger) Printf(format string, args ...interface{})
Printf logs a line with fmt.Printf semantics.
func (*PrintLogger) Println ¶ added in v0.8.0
func (l *PrintLogger) Println(v ...interface{})
Println logs a line with fmt.Println semantics.
type TestLogger ¶
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger is a simple stub for the logger interface.
The TestLogger is safe for concurrent use.
func (*TestLogger) Count ¶
func (l *TestLogger) Count() int
Count returns the number of events recorded in the logger.
func (*TestLogger) Debug ¶
func (l *TestLogger) Debug(msg string, fields ...map[string]interface{})
Debug records a Debug level event.
func (*TestLogger) Error ¶
func (l *TestLogger) Error(msg string, fields ...map[string]interface{})
Error records a Error level event.
func (*TestLogger) Events ¶
func (l *TestLogger) Events() []LogEvent
Events returns all recorded events in the logger.
func (*TestLogger) Info ¶
func (l *TestLogger) Info(msg string, fields ...map[string]interface{})
Info records a Info level event.
func (*TestLogger) LastEvent ¶
func (l *TestLogger) LastEvent() *LogEvent
LastEvent returns the last recorded event in the logger (if any).
func (*TestLogger) Trace ¶
func (l *TestLogger) Trace(msg string, fields ...map[string]interface{})
Trace records a Trace level event.
func (*TestLogger) Warn ¶
func (l *TestLogger) Warn(msg string, fields ...map[string]interface{})
Warn records a Warn level event.