logger

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

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

DefaultLogger is the default implementation of the LoggerInterface.

func NewDefaultLogger

func NewDefaultLogger() *DefaultLogger

NewDefaultLogger creates and returns a new instance of DefaultLogger.

func (*DefaultLogger) Blank

func (l *DefaultLogger) Blank()

Blank prints a blank line

func (*DefaultLogger) Default

func (l *DefaultLogger) Default(message string, args ...any) *LogEntry

Default creates a default-level log entry.

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(message string, args ...any) *LogEntry

Error creates an error-level log entry.

func (*DefaultLogger) Hint

func (l *DefaultLogger) Hint(message string, args ...any) *LogEntry

Hint creates an hint-level log entry.

func (*DefaultLogger) Info

func (l *DefaultLogger) Info(message string, args ...any) *LogEntry

Info creates an info-level log entry.

func (*DefaultLogger) Reset

func (l *DefaultLogger) Reset()

Reset resets the DefaultLogger to its default state.

func (*DefaultLogger) Success

func (l *DefaultLogger) Success(message string, args ...any) *LogEntry

Success creates a success-level log entry.

func (*DefaultLogger) Warning

func (l *DefaultLogger) Warning(message string, args ...any) *LogEntry

Warning creates a warning-level log entry.

func (*DefaultLogger) WithIndent

func (l *DefaultLogger) WithIndent(enabled bool)

WithIndent enables or disables message indentation.

func (*DefaultLogger) WithTimestamp

func (l *DefaultLogger) WithTimestamp(enabled bool)

WithTimestamp enables or disables timestamps for log entries.

type KeyValue

type KeyValue struct {
	Key   string
	Value any
}

KeyValue represents a key-value pair for attributes.

type LogEntry

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

LogEntry represents a single log message entry.

func (*LogEntry) ToJSON

func (e *LogEntry) ToJSON() (string, error)

ToJSON converts the log entry into a JSON string.

func (*LogEntry) WithAttrs

func (e *LogEntry) WithAttrs(attrs ...any) *LogEntry

WithAttrs adds attributes to the log entry and prints the entry.

type LogHandler

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

LogHandler adapts the core logger to the slog.Handler interface.

func NewLogHandler

func NewLogHandler(logger LoggerInterface) *LogHandler

NewLogHandler creates a new LogHandler instance.

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(_ context.Context, _ slog.Level) bool

Enabled determines whether the handler is enabled for the given log level.

func (*LogHandler) Handle

func (h *LogHandler) Handle(ctx context.Context, record slog.Record) error

Handle processes a slog.Record and routes it to the core logger.

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs is a no-op for this handler.

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

WithGroup creates a new grouped handler.

type LogWriter

type LogWriter struct {
	Level  string
	Logger LoggerInterface
}

func (*LogWriter) Write

func (lw *LogWriter) Write(p []byte) (n int, err error)

type LoggerInterface

type LoggerInterface interface {
	Default(message string, args ...any) *LogEntry
	Info(message string, args ...any) *LogEntry
	Success(message string, args ...any) *LogEntry
	Warning(message string, args ...any) *LogEntry
	Error(message string, args ...any) *LogEntry
	Hint(message string, args ...any) *LogEntry
	Blank()
	WithTimestamp(enabled bool)
	WithIndent(enabled bool)
	Reset()
}

LoggerInterface defines the interface for structured logging.

Jump to

Keyboard shortcuts

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