logger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LevelLogger

type LevelLogger interface {
	// Debug handles logging the given message at the debug level.
	Debug(msg string, args ...any)

	// Info handles logging the given message at the info level.
	Info(msg string, args ...any)

	// Warn handles logging the given message at the warn level.
	Warn(msg string, args ...any)

	// Error handles logging the given message at the error level.
	Error(msg string, args ...any)

	// WithGroup creates a new child/group Logger from the current logger.
	WithGroup(group string) LevelLogger

	// Verbose returns true if the logger is in verbose mode.
	Verbose() bool
}

LevelLogger is a logger that supports different levels of logging.

type Logger

type Logger struct {
	// Level is the log Level to use for
	// filtering log verbosity.
	Level slog.Level

	// Slogger is the underlying slog.Logger
	// that is used for logging.
	Slogger *slog.Logger
	// contains filtered or unexported fields
}

Logger is a wrapper around slog.Logger.

func New

func New(name string, opts ...Option) *Logger

New returns a new Logger with the given name and level.

func (*Logger) Debug

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

Debug handles proxying the given message to the underlying slog.Logger at the debug level.

func (*Logger) Error

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

Error handles proxying the given message to the underlying slog.Logger at the error level.

func (*Logger) Info

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

Info handles proxying the given message to the underlying slog.Logger at the info level.

func (*Logger) Verbose

func (l *Logger) Verbose() bool

Verbose returns true if the logger is in verbose mode.

func (*Logger) Warn

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

Warn handles proxying the given message to the underlying slog.Logger at the warn level.

func (*Logger) WithGroup

func (l *Logger) WithGroup(group string) LevelLogger

WithGroup creates a new child/group Logger from the current logger.

type NoopLogger

type NoopLogger struct{}

NoopLogger is a logger that does nothing.

func (*NoopLogger) Debug

func (l *NoopLogger) Debug(msg string, args ...any)

Debug handles logging the given message at the debug level.

func (*NoopLogger) Error

func (l *NoopLogger) Error(msg string, args ...any)

Error handles logging the given message at the error level.

func (*NoopLogger) Info

func (l *NoopLogger) Info(msg string, args ...any)

Info handles logging the given message at the info level.

func (*NoopLogger) Verbose

func (l *NoopLogger) Verbose() bool

Verbose returns true if the logger is in verbose mode.

func (*NoopLogger) Warn

func (l *NoopLogger) Warn(msg string, args ...any)

Warn handles logging the given message at the warn level.

func (*NoopLogger) WithGroup

func (l *NoopLogger) WithGroup(group string) LevelLogger

WithGroup creates a new child/group Logger from the current logger.

type Option

type Option func(*Logger)

func WithHandler

func WithHandler(h slog.Handler) Option

WithHandler sets the handler for the logger.

func WithVerbose

func WithVerbose(v bool) Option

WithVerbose sets the logger to verbose mode by way of setting the log level to debug.

Jump to

Keyboard shortcuts

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