log

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

Level represents the severity of a log message

const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	FATAL
)

type LogConfig added in v0.9.5

type LogConfig struct {
	// Driver specifies the log driver: "console" or "file".
	Driver string
	// Config holds driver-specific options (e.g., "path" for file driver).
	Config map[string]any
}

LogConfig holds configuration for creating a Logger instance.

func LogConfigFromEnv added in v0.9.5

func LogConfigFromEnv() LogConfig

LogConfigFromEnv builds a LogConfig from environment variables. It reads LOG_DRIVER, LOG_PATH, LOG_LEVEL, and LOG_FORMAT.

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 NewLogger added in v0.9.5

func NewLogger(config LogConfig) (Logger, error)

NewLogger creates a new Logger instance with the given configuration. This is the preferred way to create loggers instead of using the global Init().

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