log

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLevelNotRecognised     = errors.New("level is not recognised")
	ErrLevelIntegerOutOfRange = errors.New("level integer can only be between 0 and 5 included")
)

Functions

func Errorf

func Errorf(s string, args ...interface{})

Errorf using the global logger, only used in test main runners initialisation error.

func Patch

func Patch(options ...Option)

Patch patches the global logger.

Types

type Format

type Format uint8

Format is the format to use.

const (
	// FormatConsole is the default human readable console format.
	FormatConsole Format = iota
)

type Level

type Level uint8

Level is the level of the logger.

const (
	// Critical is the cirtical (crit) level.
	Critical Level = iota
	// Error is the error (eror) level.
	Error
	// Warn is the warn level.
	Warn
	// Info is the info level.
	Info
	// Debug is the debug (dbug) level.
	Debug
	// Trace is the trace (trce) level.
	Trace
	// DoNotChange indicates the level of the logger should be
	// left as is.
	DoNotChange Level = Level(^uint8(0))
)

func ParseLevel

func ParseLevel(s string) (level Level, err error)

ParseLevel parses a string into a level, and returns an error if it fails. It accepts integers between 0 (critical) and 5 (trace) as well as strings such as 'trace' or 'dbug'.

func (Level) String

func (level Level) String() (s string)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is the logger implementation structure. It is thread safe to use.

func New

func New(options ...Option) *Logger

New creates a new logger. It can only be called once per writer. If you want to create more loggers with different settings for the same writer, child loggers can be created using the New(options) method, to ensure thread safety on the same writer.

func NewFromGlobal

func NewFromGlobal(options ...Option) *Logger

NewFromGlobal creates a child logger from the global logger.

func (*Logger) Critical

func (l *Logger) Critical(s string)

Critical logs with the crit level.

func (*Logger) Criticalf

func (l *Logger) Criticalf(format string, args ...interface{})

Criticalf formats and logs at the crit level.

func (*Logger) Debug

func (l *Logger) Debug(s string)

Debug logs with the dbug level.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf formats and logs at the dbug level.

func (*Logger) Error

func (l *Logger) Error(s string)

Error logs with the eror level.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf formats and logs at the eror level.

func (*Logger) Info

func (l *Logger) Info(s string)

Info logs with the info level.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof formats and logs at the info level.

func (*Logger) New

func (l *Logger) New(options ...Option) *Logger

New creates a new thread safe child logger. It can use a different writer, but it is expected to use the same writer since it is thread safe.

func (*Logger) Patch

func (l *Logger) Patch(options ...Option)

Patch patches the existing settings with any option given. This is thread safe and propagates to all child loggers. TODO-1946 remove patch progagation to child loggers.

func (*Logger) Trace

func (l *Logger) Trace(s string)

Trace logs with the trce level.

func (*Logger) Tracef

func (l *Logger) Tracef(format string, args ...interface{})

Tracef formats and logs at the trce level.

func (*Logger) Warn

func (l *Logger) Warn(s string)

Warn logs with the warn level.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf formats and logs at the warn level.

type Option

type Option func(s *settings)

Option is the type to specify settings modifier for the logger operation.

func AddContext

func AddContext(key, value string) Option

AddContext adds the context for the logger as a key values pair. It adds them in order. If a key already exists, the value is added to the existing values.

func SetCallerFile

func SetCallerFile(enabled bool) Option

SetCallerFile enables or disables logging the caller file. The default is disabled.

func SetCallerFunc

func SetCallerFunc(enabled bool) Option

SetCallerFunc enables or disables logging the caller function. The default is disabled.

func SetCallerLine

func SetCallerLine(enabled bool) Option

SetCallerLine enables or disables logging the caller line number. The default is disabled.

func SetFormat

func SetFormat(format Format) Option

SetFormat set the format for the logger. The format defaults to FormatConsole.

func SetLevel

func SetLevel(level Level) Option

SetLevel sets the level for the logger. The level defaults to the lowest level, trce.

func SetWriter

func SetWriter(writer io.Writer) Option

SetWriter set the writer for the logger. The writer defaults to os.Stdout.

Jump to

Keyboard shortcuts

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