log

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
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

View Source
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

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

NewContextWithLogger returns a new context with the given logger.

func Warn added in v0.9.0

func Warn(kv ...interface{})

Warn logs a warn level message to the default 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).

func ToFormat added in v0.8.0

func ToFormat(f string) Format

ToFormat translates the given format as a string to a Format.

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.

func ToLevel

func ToLevel(l string) Level

ToLevel translates the given level as a string to a Level.

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

func LoggerFromContext(ctx context.Context) Logger

LoggerFromContext returns the logger for the current request.

func New

func New(opts ...Option) (Logger, error)

New returns a Logger.

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.

func (Logger) Level added in v0.17.0

func (l Logger) Level() Level

Level returns the log level.

func (Logger) Warn added in v0.8.0

func (l Logger) Warn(kv ...interface{})

Warn logs a warn level message.

func (Logger) With added in v0.8.0

func (l Logger) With(kv ...interface{}) Logger

With returns a new contextual logger with keyvals prepended to those passed to calls to log.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option provides for Logger configuration.

func AsDefault

func AsDefault() Option

As default sets the DefaultLogger.

func WithFormat added in v0.8.0

func WithFormat(format Format) Option

WithFormat allows the format to be configured. The default format is FormatLogfmt.

func WithLevel

func WithLevel(level Level) Option

WithLevel allows the level to be configured. The default level is LevelInfo.

func WithOutput

func WithOutput(writer io.Writer) Option

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 NewStringBuffer

func NewStringBuffer() *StringBuffer

NewStringBuffer returns a StringBuffer.

func (*StringBuffer) Index

func (l *StringBuffer) Index(i int) string

func (*StringBuffer) Len

func (l *StringBuffer) Len() int

func (*StringBuffer) Write

func (l *StringBuffer) Write(p []byte) (int, error)

Write implements the io.Writer interface.

Jump to

Keyboard shortcuts

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