logger

package module
v4.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 10 Imported by: 0

README

go-logger

Simplistic, performant, opinionated levelled logging package.

Pass -tags=kvformat to your build to use the custom formatter in go-kv when printing fields (see package for more details).

Import with "codeberg.org/gruf/go-logger/v4". Only v4 is supported going forward.

Documentation

Index

Constants

View Source
const (
	// Logger entry formatting flags.
	LTimestamp = uint32(1) << 1
	LCaller    = uint32(1) << 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Lvl  LEVEL
	Data []kv.Field
	Msg  string
	Out  *Logger
}

func (Entry) Debug

func (e Entry) Debug(args ...interface{})

func (Entry) DebugKVs

func (e Entry) DebugKVs(fields ...kv.Field)

func (Entry) Debugf

func (e Entry) Debugf(msg string, args ...interface{})

func (Entry) Error

func (e Entry) Error(args ...interface{})

func (Entry) ErrorKVs

func (e Entry) ErrorKVs(fields ...kv.Field)

func (Entry) Errorf

func (e Entry) Errorf(msg string, args ...interface{})

func (Entry) Info

func (e Entry) Info(args ...interface{})

func (Entry) InfoKVs

func (e Entry) InfoKVs(fields ...kv.Field)

func (Entry) Infof

func (e Entry) Infof(msg string, args ...interface{})

func (Entry) Panic

func (e Entry) Panic(args ...interface{})

func (Entry) PanicKVs

func (e Entry) PanicKVs(fields ...kv.Field)

func (Entry) Panicf

func (e Entry) Panicf(msg string, args ...interface{})

func (Entry) Trace

func (e Entry) Trace(args ...interface{})

func (Entry) TraceKVs

func (e Entry) TraceKVs(fields ...kv.Field)

func (Entry) Tracef

func (e Entry) Tracef(msg string, args ...interface{})

func (Entry) Warn

func (e Entry) Warn(args ...interface{})

func (Entry) WarnKVs

func (e Entry) WarnKVs(fields ...kv.Field)

func (Entry) Warnf

func (e Entry) Warnf(msg string, args ...interface{})

func (Entry) With

func (e Entry) With(fields ...kv.Field) Entry

func (Entry) Write

func (e Entry) Write(calldepth int)

type LEVEL

type LEVEL uint8

LEVEL defines a level of logging.

const (
	UNSET LEVEL = 0
	PANIC LEVEL = 50
	ERROR LEVEL = 100
	WARN  LEVEL = 150
	INFO  LEVEL = 200
	DEBUG LEVEL = 250
	TRACE LEVEL = 254
	ALL   LEVEL = ^LEVEL(0)
)

Default levels of logging.

func ParseLevel

func ParseLevel(s string) (LEVEL, error)

ParseLevel will attempt to decode LEVEL from given string, checking (case insensitive) against strings in Levels.

func (LEVEL) CanLog

func (loglvl LEVEL) CanLog(lvl LEVEL) bool

CanLog returns whether an incoming log of 'lvl' can be logged against receiving level.

type Logger

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

func New

func New(opts ...Option) *Logger

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) DebugKVs

func (l *Logger) DebugKVs(fields ...kv.Field)

func (*Logger) Debugf

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

func (*Logger) Entry

func (l *Logger) Entry() Entry

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) ErrorKVs

func (l *Logger) ErrorKVs(fields ...kv.Field)

func (*Logger) Errorf

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

func (*Logger) Flags

func (l *Logger) Flags() uint32

Flags returns the currently set logger flags.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) InfoKVs

func (l *Logger) InfoKVs(fields ...kv.Field)

func (*Logger) Infof

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

func (*Logger) Level

func (l *Logger) Level() LEVEL

Level returns the minimum logging level for the logger.

func (*Logger) Output

func (l *Logger) Output(calldepth int, lvl LEVEL, msg string)

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

func (*Logger) PanicKVs

func (l *Logger) PanicKVs(fields ...kv.Field)

func (*Logger) Panicf

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

func (*Logger) Print

func (l *Logger) Print(args ...interface{})

func (*Logger) PrintKVs

func (l *Logger) PrintKVs(fields ...kv.Field)

func (*Logger) Printf

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

func (*Logger) SetFlags

func (l *Logger) SetFlags(flags uint32)

SetFlags sets the flags for the logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl LEVEL)

SetLevel sets the minimum logging level for the logger.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger.

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{})

func (*Logger) TraceKVs

func (l *Logger) TraceKVs(fields ...kv.Field)

func (*Logger) Tracef

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

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) WarnKVs

func (l *Logger) WarnKVs(fields ...kv.Field)

func (*Logger) Warnf

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

func (*Logger) Write

func (l *Logger) Write(calldepth int, lvl LEVEL, write func(*byteutil.Buffer))

Write will output the contents of buffer after write function, at level using supplied calldepth for caller calculation.

Note this function cannot be inlined, to ensure expected and consistent behaviour in setting trace / caller info.

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the output destination for the logger.

type Option

type Option interface {
	Apply(*Logger)
}

func WithCaller

func WithCaller(enabled bool) Option

func WithClock

func WithClock(now func() string) Option

func WithLevel

func WithLevel(lvl LEVEL) Option

func WithOutput

func WithOutput(out io.Writer) Option

func WithSafeOutput

func WithSafeOutput(out io.Writer) Option

func WithTimestamp

func WithTimestamp(enabled bool) Option

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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