Documentation
¶
Overview ¶
Package logger provides a platform-agnostic logging interface for WarpDL. It supports multiple backends including console output and Windows Event Log.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToStdLogger ¶
ToStdLogger creates a *log.Logger that writes through the given Logger interface. This bridges the Logger interface with code that expects *log.Logger. Useful for integrating with existing code that uses the standard library logger.
Types ¶
type Logger ¶
type Logger interface {
// Info logs an informational message (e.g., "Service started").
Info(format string, args ...interface{})
// Warning logs a warning message (e.g., "Retry attempt 2/3").
Warning(format string, args ...interface{})
// Error logs an error message (e.g., "Failed to start server: connection refused").
Error(format string, args ...interface{})
// Close releases resources held by the logger (e.g., Windows Event Log handle).
// Safe to call multiple times. Returns nil for loggers without resources.
Close() error
}
Logger defines the interface for structured logging across all WarpDL components. Implementations may log to console, files, Windows Event Log, or syslog.
type MockLogger ¶
type MockLogger struct {
InfoCalls []string
WarningCalls []string
ErrorCalls []string
CloseCalled bool
}
MockLogger implements Logger for testing purposes. It records all log calls for verification in tests.
func NewMockLogger ¶
func NewMockLogger() *MockLogger
NewMockLogger creates a new MockLogger for testing.
func (*MockLogger) Error ¶
func (m *MockLogger) Error(format string, args ...interface{})
Error records the formatted message.
func (*MockLogger) Info ¶
func (m *MockLogger) Info(format string, args ...interface{})
Info records the formatted message.
func (*MockLogger) Warning ¶
func (m *MockLogger) Warning(format string, args ...interface{})
Warning records the formatted message.
type MultiLogger ¶
type MultiLogger struct {
// contains filtered or unexported fields
}
MultiLogger broadcasts log messages to multiple Logger backends. Useful for logging to both console and Windows Event Log simultaneously.
func NewMultiLogger ¶
func NewMultiLogger(loggers ...Logger) *MultiLogger
NewMultiLogger creates a logger that writes to all provided backends. Messages are written to each logger in order. Errors from individual loggers are ignored to ensure all backends receive the message.
func (*MultiLogger) Close ¶
func (m *MultiLogger) Close() error
Close closes all logger backends. Returns the first error encountered, but attempts to close all loggers.
func (*MultiLogger) Error ¶
func (m *MultiLogger) Error(format string, args ...interface{})
Error logs an error message to all backends.
func (*MultiLogger) Info ¶
func (m *MultiLogger) Info(format string, args ...interface{})
Info logs an informational message to all backends.
func (*MultiLogger) Warning ¶
func (m *MultiLogger) Warning(format string, args ...interface{})
Warning logs a warning message to all backends.
type NopLogger ¶
type NopLogger struct{}
NopLogger is a logger that discards all messages. Useful for testing or when logging should be disabled.
func NewNopLogger ¶
func NewNopLogger() *NopLogger
NewNopLogger creates a logger that discards all messages.
type StandardLogger ¶
type StandardLogger struct {
// contains filtered or unexported fields
}
StandardLogger wraps the stdlib *log.Logger for console/file output. Used when running as a console application (non-service mode).
func NewStandardLogger ¶
func NewStandardLogger(l *log.Logger) *StandardLogger
NewStandardLogger creates a logger that wraps the given *log.Logger. Enables gradual migration from existing log.Default() usage.
func (*StandardLogger) Close ¶
func (s *StandardLogger) Close() error
Close is a no-op for StandardLogger (no resources to release).
func (*StandardLogger) Error ¶
func (s *StandardLogger) Error(format string, args ...interface{})
Error logs an error message with [ERROR] prefix.
func (*StandardLogger) Info ¶
func (s *StandardLogger) Info(format string, args ...interface{})
Info logs an informational message with [INFO] prefix.
func (*StandardLogger) Warning ¶
func (s *StandardLogger) Warning(format string, args ...interface{})
Warning logs a warning message with [WARNING] prefix.