log

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SkipAttr = slog.Attr{}
)

Functions

func CtxAppendLoggerAttrs

func CtxAppendLoggerAttrs(ctx context.Context, attrs ...slog.Attr) context.Context

CtxAppendLoggerAttrs adds the given attributes to the context, it will append to any existing attributes.

func CtxWithLoggerAttrs

func CtxWithLoggerAttrs(ctx context.Context, attrs ...slog.Attr) context.Context

CtxWithLoggerAttrs sets the given attributes to the context, it will overwrite any existing attributes.

func GetLoggerAttrsFromCtx

func GetLoggerAttrsFromCtx(ctx ValueContext) []slog.Attr

GetLoggerAttrsFromCtx returns the attributes from the context, or nil if there are none.

func NewSlogLogger

func NewSlogLogger(logger Logger) *slog.Logger

func SetDefaultLoggerFactory

func SetDefaultLoggerFactory(f *LoggerFactory)

SetDefaultLoggerFactory sets the default logger factory to use for the package-level functions.

Types

type Logger

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

Logger structure

func GetLogger

func GetLogger() Logger

GetLogger returns a logger for the caller using the default logger factory.

func GetLoggerForPath

func GetLoggerForPath(pth string) Logger

GetLoggerForPath returns a logger for the given path and adds the context properties (if any) using the default logger factory.

func GetLoggerForType

func GetLoggerForType(forType any) Logger

GetLoggerForType returns a logger for the given type and adds the context properties (if any) using the default logger factory.

func GetLoggerFromCtx

func GetLoggerFromCtx(ctx ValueContext) Logger

GetLoggerFromCtx returns a logger for the caller and adds the context properties (if any). Default logger Factory will be used if there is none in the context.

func GetLoggerFromCtxForPath

func GetLoggerFromCtxForPath(ctx ValueContext, pth string) Logger

GetLoggerFromCtxForPath returns a logger for the given path and adds the context properties (if any) using the default logger factory.

func GetLoggerFromCtxForType

func GetLoggerFromCtxForType(ctx ValueContext, forType any) Logger

GetLoggerFromCtxForType returns a logger for the given type and adds the context properties (if any) using

func GetRootLogger

func GetRootLogger() Logger

GetRootLogger returns the root logger using the default logger factory.

func NewLogger

func NewLogger(conf config.RootConfig, name string) Logger

NewLogger creates a new logger with the given core configuration.

func NewLoggerWithWriter

func NewLoggerWithWriter(conf config.RootConfig, name string, writer io.Writer) Logger

NewLoggerWithWriter creates a new logger with the given core configuration and writer.

func (Logger) Debug

func (l Logger) Debug(msg string, args ...any)

func (Logger) Debugf

func (l Logger) Debugf(format string, args ...any)

func (Logger) Enabled

func (l Logger) Enabled(level config.LogLevel) bool

Enabled returns true if the given level is enabled.

func (Logger) Error

func (l Logger) Error(msg string, args ...any)

func (Logger) ErrorE

func (l Logger) ErrorE(err error)

func (Logger) Errorf

func (l Logger) Errorf(format string, args ...any)

func (Logger) Info

func (l Logger) Info(msg string, args ...any)

func (Logger) Infof

func (l Logger) Infof(format string, args ...any)

func (Logger) Level

func (l Logger) Level() config.LogLevel

Level returns the current log level.

func (Logger) Log

func (l Logger) Log(level config.LogLevel, msg string, args ...any)

func (Logger) LogAttrs

func (l Logger) LogAttrs(level config.LogLevel, msg string, attrs ...slog.Attr)

func (Logger) SetLevel

func (l Logger) SetLevel(level config.LogLevel)

SetLevel updates the current log level.

func (Logger) Trace

func (l Logger) Trace(msg string, args ...any)

func (Logger) Tracef

func (l Logger) Tracef(format string, args ...any)

func (Logger) Warn

func (l Logger) Warn(msg string, args ...any)

func (Logger) Warnf

func (l Logger) Warnf(format string, args ...any)

func (Logger) With

func (l Logger) With(args ...any) Logger

With returns a new logger with the given attributes.

func (Logger) WithAttrs

func (l Logger) WithAttrs(attrs ...slog.Attr) Logger

WithAttrs returns a new logger with the given attributes.

func (Logger) WithContext

func (l Logger) WithContext(ctx context.Context) Logger

WithContext returns a new logger with the given context.

func (Logger) Writer

func (l Logger) Writer() io.Writer

Writer returns the writer used by the logger.

type LoggerFactory

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

func GetDefaultLoggerFactory

func GetDefaultLoggerFactory() *LoggerFactory

GetDefaultLoggerFactory returns the default logger factory used by the package-level functions.

func NewLoggerFactory

func NewLoggerFactory(coreConfig config.RootConfig) *LoggerFactory

NewLoggerFactory creates a new logger factory with the given core configuration.

func NewLoggerFactoryWithWriter

func NewLoggerFactoryWithWriter(coreConfig config.RootConfig, writer io.Writer) *LoggerFactory

NewLoggerFactoryWithWriter creates a new logger factory with the given core configuration and writer.

func (*LoggerFactory) GetLogger

func (lf *LoggerFactory) GetLogger() Logger

GetLogger returns a logger for the caller

func (*LoggerFactory) GetLoggerForPath

func (lf *LoggerFactory) GetLoggerForPath(pth string) Logger

GetLoggerForPath returns a logger for the given path and adds the context properties (if any).

func (*LoggerFactory) GetLoggerForType

func (lf *LoggerFactory) GetLoggerForType(forType any) Logger

GetLoggerForType returns a logger for the given type and adds the context properties (if any).

func (*LoggerFactory) GetLoggerFromCtx

func (lf *LoggerFactory) GetLoggerFromCtx(ctx ValueContext) Logger

GetLoggerFromCtx returns a logger for the caller and adds the context properties (if any)

func (*LoggerFactory) GetLoggerFromCtxForPath

func (lf *LoggerFactory) GetLoggerFromCtxForPath(ctx ValueContext, pth string) Logger

GetLoggerFromCtxForPath returns a logger for the given type and adds the context properties (if any)

func (*LoggerFactory) GetLoggerFromCtxForType

func (lf *LoggerFactory) GetLoggerFromCtxForType(ctx ValueContext, forType any) Logger

GetLoggerFromCtxForType returns a logger for the given type and adds the context properties (if any)

func (*LoggerFactory) GetRootLogger

func (lf *LoggerFactory) GetRootLogger() Logger

GetRootLogger returns the root logger. This is a shortcut for GetLoggerForPath("/").

func (*LoggerFactory) SetCtx

func (lf *LoggerFactory) SetCtx(ctx context.Context) context.Context

type ValueContext

type ValueContext interface{ Value(any) any }

Jump to

Keyboard shortcuts

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