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 ¶
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.
type Option ¶ added in v0.8.0
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 WithLevel ¶ added in v0.8.0
WithLevel allows the level to be configured. The default level is LevelInfo.
func WithOutput ¶ added in v0.8.0
WithOutput allows the format to be configured. The default writer is os.Stdout.
func WithoutTimestamp ¶ added in v0.9.0
func WithoutTimestamp() Option
WithoutTimestamp disables the use of a timestamp for logs. Useful for unit tests.
type StringBuffer ¶ added in v0.15.0
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 NewStringBuffer ¶ added in v0.15.0
func NewStringBuffer() *StringBuffer
NewStringBuffer returns a StringBuffer.
func (*StringBuffer) Index ¶ added in v0.15.0
func (l *StringBuffer) Index(i int) string
func (*StringBuffer) Len ¶ added in v0.15.0
func (l *StringBuffer) Len() int