Documentation
¶
Index ¶
Constants ¶
const ( // LevelDebug provides the most verbose logging, allowing logs for debug, info, // warn, and error. LevelDebug Level = iota // LevelInfo is the default log level. It allows logs for info, warn, and // error. LevelInfo // LevelWarn is reserved for logging warnings and errors. LevelWarn // LevelError provides the least verbose logging, allowing logs only for // errors. LevelError // LevelInvalid indicates and invalid log level. LevelInvalid // FormatJSON encodes each log entry as a single JSON object. FormatJSON Format = iota // FormatLogfmt encodes each log entry in logfmt format. FormatLogfmt // FormatNop will suppress logging output entirely. FormatNop // FormatInvalid indicates an invalid log format. FormatInvalid )
Variables ¶
var ( // ErrInvalidLevel will be returned when the level given to the WirhLevel // option is invalid. ErrInvalidLevel = errors.New("invalid level") // ErrInvalidFormat will be returned when the format given to the WithFormat // options is invalid. ErrInvalidFormat = errors.New("invalid format") // ErrInvalidOutput will be returned when the output writer given to WithOuput // is nil. ErrInvalidOutput = errors.New("invalid output") )
Functions ¶
func Debug ¶ added in v0.9.0
func Debug(kv ...interface{})
Debug logs an debug level message to the default logger.
func Error ¶ added in v0.9.0
func Error(kv ...interface{})
Error logs an error level message to the default logger.
func Info ¶ added in v0.9.0
func Info(kv ...interface{})
Info logs an info level message to the default logger.
func NewContextWithLogger ¶ added in v0.8.0
NewContextWithLogger returns a new context with the given logger.
Types ¶
type Format ¶ added in v0.8.0
type Format uint
Format defines the output formats of the logger. Supported formats are FormatLogfmt (the default), FormatJSON, and FormatNop (no logging).
type Level ¶ added in v0.8.0
type Level uint
Level defines the logging levels available to the Logger, with a level of debug logging all message and error logging only error message.
type Logger ¶ added in v0.1.0
type Logger struct {
// contains filtered or unexported fields
}
Logger is the interface for all logging operations.
var (
DefaultLogger Logger
)
func LoggerFromContext ¶ added in v0.8.0
LoggerFromContext returns the logger for the current request.
func (Logger) Debug ¶ added in v0.1.0
func (l Logger) Debug(kv ...interface{})
Debug logs a debug level message.
func (Logger) Error ¶ added in v0.1.0
func (l Logger) Error(kv ...interface{})
Error logs an error level message.
func (Logger) Info ¶ added in v0.1.0
func (l Logger) Info(kv ...interface{})
Info logs an info level message.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option provides for Logger configuration.
func WithFormat ¶ added in v0.8.0
WithFormat allows the format to be configured. The default format is FormatLogfmt.
func WithOutput ¶
WithOutput allows the format to be configured. The default writer is os.Stdout.
func WithoutTimestamp ¶
func WithoutTimestamp() Option
WithoutTimestamp disables the use of a timestamp for logs. Useful for unit tests.
type StringBuffer ¶
type StringBuffer struct {
// contains filtered or unexported fields
}
StringBuffer implements a simple buffer that can be used in tests. It implements the io.Writer interface. Each write will append a string to the Buffer.
func (*StringBuffer) Index ¶
func (l *StringBuffer) Index(i int) string
func (*StringBuffer) Len ¶
func (l *StringBuffer) Len() int