logging

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileRotationConfig added in v0.3.0

type FileRotationConfig struct {
	Path       string // Log file path (required)
	MaxSizeMB  int    // Maximum size in megabytes before rotation (default: 100)
	MaxBackups int    // Maximum number of old log files to retain (default: 3)
	MaxAge     int    // Maximum number of days to retain old log files (default: 28)
	Compress   bool   // Whether to compress rotated log files (default: false)
}

FileRotationConfig contains file logging rotation settings

type Level

type Level int

Level represents log level

const (
	// LevelDebug is for debug messages
	LevelDebug Level = iota
	// LevelInfo is for informational messages
	LevelInfo
	// LevelWarn is for warning messages
	LevelWarn
	// LevelError is for error messages
	LevelError
	// LevelFatal is for fatal error messages
	LevelFatal
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a string into a Level

func (Level) String

func (l Level) String() string

String returns the string representation of the log level

type Logger

type Logger interface {
	Debug(msg string, args ...interface{})
	Info(msg string, args ...interface{})
	Warn(msg string, args ...interface{})
	Error(msg string, args ...interface{})
	Fatal(msg string, args ...interface{})
	WithModule(module string) Logger
}

Logger is the interface for logging

type SimpleLogger

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

SimpleLogger is a basic logger implementation

func NewLoggerWithFile added in v0.3.0

func NewLoggerWithFile(module string, level Level, useColors bool, fileConfig *FileRotationConfig) (*SimpleLogger, error)

NewLoggerWithFile creates a logger that writes to both console and file with rotation When file logging is enabled, colors are always disabled for file output to avoid ANSI escape codes in log files

func NewSimpleLogger

func NewSimpleLogger(module string, level Level, useColors bool) *SimpleLogger

NewSimpleLogger creates a new SimpleLogger writing to stdout

func NewSimpleLoggerWithWriter added in v0.3.0

func NewSimpleLoggerWithWriter(module string, level Level, useColors bool, writer io.Writer) *SimpleLogger

NewSimpleLoggerWithWriter creates a new SimpleLogger with a custom io.Writer

func (*SimpleLogger) Debug

func (l *SimpleLogger) Debug(msg string, args ...interface{})

Debug logs a debug message

func (*SimpleLogger) Error

func (l *SimpleLogger) Error(msg string, args ...interface{})

Error logs an error message

func (*SimpleLogger) Fatal

func (l *SimpleLogger) Fatal(msg string, args ...interface{})

Fatal logs a fatal error message and exits

func (*SimpleLogger) Info

func (l *SimpleLogger) Info(msg string, args ...interface{})

Info logs an informational message

func (*SimpleLogger) Warn

func (l *SimpleLogger) Warn(msg string, args ...interface{})

Warn logs a warning message

func (*SimpleLogger) WithModule

func (l *SimpleLogger) WithModule(module string) Logger

WithModule creates a new logger with a hierarchical component name. If the current logger already has a component (module), the new component is appended with "/" as a separator (e.g., "proxy/middleware/session"). This allows tracing the origin of log messages through component hierarchy.

type TestLogger

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

TestLogger is a logger for testing that suppresses output

func NewTestLogger

func NewTestLogger() *TestLogger

NewTestLogger creates a new test logger that suppresses output If you need to see logs during tests, use NewTestLoggerVerbose instead

func NewTestLoggerVerbose

func NewTestLoggerVerbose(t *testing.T) *TestLogger

NewTestLoggerVerbose creates a test logger that outputs to testing.T

func (*TestLogger) Debug

func (l *TestLogger) Debug(msg string, args ...interface{})

Debug logs a debug message

func (*TestLogger) Error

func (l *TestLogger) Error(msg string, args ...interface{})

Error logs an error message

func (*TestLogger) Fatal

func (l *TestLogger) Fatal(msg string, args ...interface{})

Fatal logs a fatal error message (but doesn't exit in tests)

func (*TestLogger) Info

func (l *TestLogger) Info(msg string, args ...interface{})

Info logs an informational message

func (*TestLogger) Warn

func (l *TestLogger) Warn(msg string, args ...interface{})

Warn logs a warning message

func (*TestLogger) WithModule

func (l *TestLogger) WithModule(module string) Logger

WithModule creates a new logger with a hierarchical component name. If the current logger already has a component (module), the new component is appended with "/" as a separator (e.g., "proxy/middleware/session").

Jump to

Keyboard shortcuts

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