log

package
Version: v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: Apache-2.0 Imports: 8 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("Invvalid Format")

	// ErrInvalidOutput will be returned when the output writer given to WithOuput
	// is nil.
	ErrInvalidOutput = errors.New("Invalid Format")
)

Functions

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.

Types

type Format added in v0.8.0

type Format uint

Format defines the output formats of the logger. Supported formats are FormatJSON (the default), FormatLogfmt, and FormatNop (no loggin).

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 added in v0.8.0

func ToLevel(l string) Level

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

type Logger

type Logger interface {
	// Debug logs a debug level message.
	Debug(...interface{})

	// Info logs an info level message.
	Info(...interface{})

	// Warn logs a warn level message.
	Warn(...interface{})

	// Error logs an error level message.
	Error(...interface{})

	// With returns a new contextual logger with keyvals prepended to those
	// passed to calls to log.
	With(...interface{}) Logger
}

Logger is the interface for all logging operations.

func LoggerFromContext added in v0.8.0

func LoggerFromContext(ctx context.Context) Logger

LoggerFromContext returns the logger for the current request.

func New added in v0.8.0

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

New returns a Logger.

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

func WithFormat(format Format) Option

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

func WithLevel added in v0.8.0

func WithLevel(level Level) Option

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

func WithOutput added in v0.8.0

func WithOutput(writer io.Writer) Option

WithOutput allows the format to be configured. The default writer is os.Stderr.

Source Files

Jump to

Keyboard shortcuts

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