Documentation
¶
Overview ¶
Package logger provides simple terminal output logging capabilities.
Package logger provides structured logging capabilities with JSON formatting and context support.
Index ¶
- Constants
- func Debug(msg string, args ...interface{})
- func Error(msg string, args ...interface{})
- func ErrorWithStack(err error, msg string, args ...interface{})
- func Info(msg string, args ...interface{})
- func IsDebugEnabled() bool
- func IsVerboseEnabled() bool
- func SetGlobalLogger(logger *StructuredLogger)
- func SetGlobalLoggingFlags(verbose, debug, quiet bool)
- func SetGlobalSimpleLogger(logger *SimpleLogger)
- func SimpleDebug(msg string, args ...interface{})
- func SimpleError(msg string, args ...interface{})
- func SimpleErrorWithStack(err error, msg string, args ...interface{})
- func SimpleInfo(msg string, args ...interface{})
- func SimpleWarn(msg string, args ...interface{})
- func Warn(msg string, args ...interface{})
- type CallerInfo
- type CommonLogger
- type ConsoleHandler
- type ErrorInfo
- type LogEntry
- type LogLevel
- type MultiHandler
- type PerformanceInfo
- type SimpleLogger
- func (l *SimpleLogger) Debug(msg string, args ...interface{})
- func (l *SimpleLogger) Error(msg string, args ...interface{})
- func (l *SimpleLogger) ErrorWithStack(err error, msg string, args ...interface{})
- func (l *SimpleLogger) Info(msg string, args ...interface{})
- func (l *SimpleLogger) LogPerformance(operation string, duration time.Duration, metrics map[string]interface{})
- func (l *SimpleLogger) LoggerMiddleware(next func() error) error
- func (l *SimpleLogger) Warn(msg string, args ...interface{})
- func (l *SimpleLogger) WithContext(key string, value interface{}) *SimpleLogger
- func (l *SimpleLogger) WithSession(sessionID string) *SimpleLogger
- type StructuredLogger
- func (l *StructuredLogger) Debug(msg string, args ...interface{})
- func (l *StructuredLogger) Error(msg string, args ...interface{})
- func (l *StructuredLogger) ErrorWithStack(err error, msg string, args ...interface{})
- func (l *StructuredLogger) Info(msg string, args ...interface{})
- func (l *StructuredLogger) LogPerformance(operation string, duration time.Duration, metrics map[string]interface{})
- func (l *StructuredLogger) LoggerMiddleware(next func() error) error
- func (l *StructuredLogger) Warn(msg string, args ...interface{})
- func (l *StructuredLogger) WithContext(key string, value interface{}) *StructuredLogger
- func (l *StructuredLogger) WithSession(sessionID string) *StructuredLogger
Constants ¶
const ( SimpleLevelDebug = "DEBUG" SimpleLevelInfo = "INFO" SimpleLevelWarn = "WARN" SimpleLevelError = "ERROR" )
Log level constants for simple logger (string format).
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(msg string, args ...interface{})
Debug logs a debug message using the global logger.
func Error ¶
func Error(msg string, args ...interface{})
Error logs an error message using the global logger.
func ErrorWithStack ¶
ErrorWithStack logs an error message with stack trace using the global logger.
func Info ¶
func Info(msg string, args ...interface{})
Info logs an info message using the global logger.
func IsDebugEnabled ¶
func IsDebugEnabled() bool
IsDebugEnabled returns whether global debug logging is enabled.
func IsVerboseEnabled ¶
func IsVerboseEnabled() bool
IsVerboseEnabled returns whether global verbose logging is enabled.
func SetGlobalLogger ¶
func SetGlobalLogger(logger *StructuredLogger)
SetGlobalLogger sets a global logger instance.
func SetGlobalLoggingFlags ¶
func SetGlobalLoggingFlags(verbose, debug, quiet bool)
SetGlobalLoggingFlags sets global logging flags that override config settings.
func SetGlobalSimpleLogger ¶
func SetGlobalSimpleLogger(logger *SimpleLogger)
SetGlobalSimpleLogger sets a global simple logger instance.
func SimpleDebug ¶
func SimpleDebug(msg string, args ...interface{})
SimpleDebug logs a debug message using the global logger.
func SimpleError ¶
func SimpleError(msg string, args ...interface{})
SimpleError logs an error message using the global logger.
func SimpleErrorWithStack ¶
SimpleErrorWithStack logs an error with stack trace using the global logger.
func SimpleInfo ¶
func SimpleInfo(msg string, args ...interface{})
SimpleInfo logs an info message using the global logger.
func SimpleWarn ¶
func SimpleWarn(msg string, args ...interface{})
SimpleWarn logs a warning message using the global logger.
Types ¶
type CallerInfo ¶
type CallerInfo struct {
File string `json:"file"`
Line int `json:"line"`
Function string `json:"function"`
}
CallerInfo represents caller information.
type CommonLogger ¶
type CommonLogger interface {
Debug(msg string, args ...interface{})
Info(msg string, args ...interface{})
Warn(msg string, args ...interface{})
Error(msg string, args ...interface{})
ErrorWithStack(err error, msg string, args ...interface{})
}
CommonLogger defines the common interface for both structured and simple loggers.
type ConsoleHandler ¶
type ConsoleHandler struct {
// contains filtered or unexported fields
}
ConsoleHandler provides human-readable console output.
func NewConsoleHandler ¶
func NewConsoleHandler(w io.Writer, opts *slog.HandlerOptions) *ConsoleHandler
NewConsoleHandler creates a new console handler with human-readable output.
func (*ConsoleHandler) Enabled ¶
Enabled returns whether the handler is enabled for the given level.
func (*ConsoleHandler) Handle ¶
Handle processes a log record and outputs it in human-readable format.
type ErrorInfo ¶
type ErrorInfo struct {
Type string `json:"type"`
Message string `json:"message"`
StackTrace string `json:"stackTrace,omitempty"`
Code string `json:"code,omitempty"`
}
ErrorInfo represents error information.
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
Component string `json:"component"`
SessionID string `json:"sessionId"`
Context map[string]interface{} `json:"context,omitempty"`
Caller *CallerInfo `json:"caller,omitempty"`
Error *ErrorInfo `json:"error,omitempty"`
Performance *PerformanceInfo `json:"performance,omitempty"`
}
LogEntry represents a structured log entry.
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}
MultiHandler implements slog.Handler to write to multiple handlers.
func NewMultiHandler ¶
func NewMultiHandler(handlers ...slog.Handler) *MultiHandler
NewMultiHandler creates a handler that writes to multiple handlers.
type PerformanceInfo ¶
type PerformanceInfo struct {
Duration time.Duration `json:"duration"`
MemoryUsage int64 `json:"memoryUsage"`
Operation string `json:"operation"`
Metrics map[string]interface{} `json:"metrics,omitempty"`
}
PerformanceInfo represents performance metrics.
type SimpleLogger ¶
type SimpleLogger struct {
// contains filtered or unexported fields
}
SimpleLogger provides straightforward terminal output for better readability.
func GetGlobalSimpleLogger ¶
func GetGlobalSimpleLogger() *SimpleLogger
GetGlobalSimpleLogger returns the global simple logger instance.
func NewSimpleLogger ¶
func NewSimpleLogger(component string) *SimpleLogger
NewSimpleLogger creates a new simple terminal logger.
func (*SimpleLogger) Debug ¶
func (l *SimpleLogger) Debug(msg string, args ...interface{})
Debug prints a debug message.
func (*SimpleLogger) Error ¶
func (l *SimpleLogger) Error(msg string, args ...interface{})
Error prints an error message.
func (*SimpleLogger) ErrorWithStack ¶
func (l *SimpleLogger) ErrorWithStack(err error, msg string, args ...interface{})
ErrorWithStack prints an error message with error details.
func (*SimpleLogger) Info ¶
func (l *SimpleLogger) Info(msg string, args ...interface{})
Info prints an info message.
func (*SimpleLogger) LogPerformance ¶
func (l *SimpleLogger) LogPerformance(operation string, duration time.Duration, metrics map[string]interface{})
LogPerformance prints performance information.
func (*SimpleLogger) LoggerMiddleware ¶
func (l *SimpleLogger) LoggerMiddleware(next func() error) error
LoggerMiddleware provides logging middleware functionality.
func (*SimpleLogger) Warn ¶
func (l *SimpleLogger) Warn(msg string, args ...interface{})
Warn prints a warning message.
func (*SimpleLogger) WithContext ¶
func (l *SimpleLogger) WithContext(key string, value interface{}) *SimpleLogger
WithContext adds context to the logger.
func (*SimpleLogger) WithSession ¶
func (l *SimpleLogger) WithSession(sessionID string) *SimpleLogger
WithSession sets a session ID.
type StructuredLogger ¶
type StructuredLogger struct {
// contains filtered or unexported fields
}
StructuredLogger provides advanced logging capabilities.
func GetGlobalLogger ¶
func GetGlobalLogger() *StructuredLogger
GetGlobalLogger returns the global logger instance.
func NewConsoleOnlyLogger ¶
func NewConsoleOnlyLogger(component string, level LogLevel) *StructuredLogger
NewConsoleOnlyLogger creates a logger that only outputs to console.
func NewDualLogger ¶
func NewDualLogger(component string, level LogLevel) (*StructuredLogger, error)
NewDualLogger creates a logger that outputs to both console (human-readable) and file (JSON).
func NewStructuredLogger ¶
func NewStructuredLogger(component string, level LogLevel) *StructuredLogger
NewStructuredLogger creates a new structured logger with dual output.
func (*StructuredLogger) Debug ¶
func (l *StructuredLogger) Debug(msg string, args ...interface{})
Debug logs a debug message.
func (*StructuredLogger) Error ¶
func (l *StructuredLogger) Error(msg string, args ...interface{})
Error logs an error message.
func (*StructuredLogger) ErrorWithStack ¶
func (l *StructuredLogger) ErrorWithStack(err error, msg string, args ...interface{})
ErrorWithStack logs an error with stack trace.
func (*StructuredLogger) Info ¶
func (l *StructuredLogger) Info(msg string, args ...interface{})
Info logs an info message.
func (*StructuredLogger) LogPerformance ¶
func (l *StructuredLogger) LogPerformance(operation string, duration time.Duration, metrics map[string]interface{})
LogPerformance logs performance metrics.
func (*StructuredLogger) LoggerMiddleware ¶
func (l *StructuredLogger) LoggerMiddleware(next func() error) error
LoggerMiddleware provides logging middleware functionality.
func (*StructuredLogger) Warn ¶
func (l *StructuredLogger) Warn(msg string, args ...interface{})
Warn logs a warning message.
func (*StructuredLogger) WithContext ¶
func (l *StructuredLogger) WithContext(key string, value interface{}) *StructuredLogger
WithContext adds context to the logger.
func (*StructuredLogger) WithSession ¶
func (l *StructuredLogger) WithSession(sessionID string) *StructuredLogger
WithSession sets a session ID.