log

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, kvs ...any)

Debug logs a debug-level message with optional key-value pairs

func EnsureInitialized

func EnsureInitialized()

EnsureInitialized can be called explicitly to guarantee logger initialization, though the logger auto-initializes on first use through the init() function

func Error

func Error(msg string, kvs ...any)

Error logs an error-level message with optional key-value pairs

func Fatal

func Fatal(msg string, kvs ...any)

Fatal logs a fatal-level message with optional key-value pairs and exits the program

func Info

func Info(msg string, kvs ...any)

Info logs an info-level message with optional key-value pairs

func Init

func Init(driver string, config map[string]any) error

Init initializes the global logger with the specified driver and configuration. Supported drivers: "console", "file" Config options vary by driver - file driver accepts "path" for log directory

func Warn

func Warn(msg string, kvs ...any)

Warn logs a warning-level message with optional key-value pairs

Types

type Level

type Level int

Level represents the severity of a log message

const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	FATAL
)

type Logger

type Logger interface {
	Debug(msg string, kvs ...any)
	Info(msg string, kvs ...any)
	Warn(msg string, kvs ...any)
	Error(msg string, kvs ...any)
	Fatal(msg string, kvs ...any)
}

Logger defines the interface for all log implementations

func Get

func Get() Logger

Get returns the global logger instance, creating a default console logger if needed

type Manager

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

Manager handles multiple logger channels for advanced logging scenarios. Each channel can have its own driver configuration (file, console, stack, null)

func NewManager

func NewManager(cfg config.LoggingConfig) *Manager

NewManager creates a new logger manager with the given configuration. The manager allows different log channels with independent drivers and settings

func (*Manager) Channel

func (m *Manager) Channel(name string) (Logger, error)

Channel returns a logger for the specified channel, creating it if needed. Thread-safe and uses double-checked locking for performance

func (*Manager) Default

func (m *Manager) Default() (Logger, error)

Default returns the default logger channel as configured in LoggingConfig

type NullLogger

type NullLogger struct{}

NullLogger discards all log messages without any output. Useful for testing or disabling logging for specific channels

func NewNullLogger

func NewNullLogger() *NullLogger

NewNullLogger creates a logger that silently discards all messages. No output is produced regardless of log level

func (*NullLogger) Debug

func (n *NullLogger) Debug(msg string, kvs ...any)

func (*NullLogger) Error

func (n *NullLogger) Error(msg string, kvs ...any)

func (*NullLogger) Fatal

func (n *NullLogger) Fatal(msg string, kvs ...any)

func (*NullLogger) Info

func (n *NullLogger) Info(msg string, kvs ...any)

func (*NullLogger) Warn

func (n *NullLogger) Warn(msg string, kvs ...any)

type StackLogger

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

StackLogger logs to multiple loggers simultaneously. Useful for logging to multiple destinations (e.g., file and console)

func NewStackLogger

func NewStackLogger(loggers ...Logger) *StackLogger

NewStackLogger creates a logger that writes to multiple loggers. All provided loggers will receive the same log messages

func (*StackLogger) Debug

func (s *StackLogger) Debug(msg string, kvs ...any)

Debug logs a debug message to all configured loggers

func (*StackLogger) Error

func (s *StackLogger) Error(msg string, kvs ...any)

Error logs an error message to all configured loggers

func (*StackLogger) Fatal

func (s *StackLogger) Fatal(msg string, kvs ...any)

Fatal logs a fatal message to all configured loggers

func (*StackLogger) Info

func (s *StackLogger) Info(msg string, kvs ...any)

Info logs an info message to all configured loggers

func (*StackLogger) Warn

func (s *StackLogger) Warn(msg string, kvs ...any)

Warn logs a warning message to all configured loggers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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