Documentation
¶
Overview ¶
Package logger provides infrastructure adapters for structured logging.
This package implements the Logger port from the domain layer, providing multiple logging backends with secret masking:
- ConsoleLogger: Human-readable colored output for CLI environments
- JSONLogger: Structured JSON logging for production and log aggregation
- MultiLogger: Broadcast logs to multiple loggers simultaneously
Architecture ¶
- Domain defines: Logger port interface with Debug/Info/Warn/Error/WithContext methods
- Infrastructure provides: Three concrete logger implementations with secret masking
- Application injects: Logger via dependency injection
Example Usage ¶
ConsoleLogger:
logger := logger.NewConsoleLogger(os.Stdout, "INFO")
logger.Info("workflow started", "id", "wf-123", "name", "deploy")
// Output: [INFO] workflow started id=wf-123 name=deploy
JSONLogger:
logger := logger.NewJSONLogger(os.Stdout, "DEBUG")
logger.Error("command failed", "exit_code", 1, "stderr", "not found")
// Output: {"level":"ERROR","msg":"command failed","exit_code":1,"stderr":"not found"}
MultiLogger:
console := logger.NewConsoleLogger(os.Stdout, "INFO")
jsonFile := logger.NewJSONLogger(file, "DEBUG")
multi := logger.NewMultiLogger(console, jsonFile)
multi.Info("event", "key", "value") // Logged to both outputs
Secret Masking ¶
- Automatically masks values for keys matching: SECRET_*, API_KEY*, PASSWORD*, *_TOKEN
- Masked values appear as "***MASKED***" in logs
- Prevents accidental credential leaks in log files and console output
- Applied by all logger implementations (ConsoleLogger, JSONLogger, MultiLogger)
Component: C056 Infrastructure Package Documentation Layer: Infrastructure
Index ¶
- Variables
- type ConsoleLogger
- type JSONLogger
- func (l *JSONLogger) Close() error
- func (l *JSONLogger) Debug(msg string, fields ...any)
- func (l *JSONLogger) Error(msg string, fields ...any)
- func (l *JSONLogger) Info(msg string, fields ...any)
- func (l *JSONLogger) Sync() error
- func (l *JSONLogger) Warn(msg string, fields ...any)
- func (l *JSONLogger) WithContext(ctx map[string]any) ports.Logger
- type Level
- type MultiLogger
- type NopLogger
- type SecretMasker
Constants ¶
This section is empty.
Variables ¶
var DefaultSecretPatterns = []string{
"SECRET_",
"API_KEY",
"PASSWORD",
"TOKEN",
}
DefaultSecretPatterns contains the default patterns to detect secrets.
Functions ¶
This section is empty.
Types ¶
type ConsoleLogger ¶
type ConsoleLogger struct {
// contains filtered or unexported fields
}
ConsoleLogger implements ports.Logger with human-readable console output.
func NewConsoleLogger ¶
func NewConsoleLogger(w io.Writer, level Level, useColor bool) *ConsoleLogger
NewConsoleLogger creates a console logger.
func (*ConsoleLogger) Debug ¶
func (l *ConsoleLogger) Debug(msg string, fields ...any)
func (*ConsoleLogger) Error ¶
func (l *ConsoleLogger) Error(msg string, fields ...any)
func (*ConsoleLogger) Info ¶
func (l *ConsoleLogger) Info(msg string, fields ...any)
func (*ConsoleLogger) Warn ¶
func (l *ConsoleLogger) Warn(msg string, fields ...any)
func (*ConsoleLogger) WithContext ¶
func (l *ConsoleLogger) WithContext(ctx map[string]any) ports.Logger
type JSONLogger ¶
type JSONLogger struct {
// contains filtered or unexported fields
}
JSONLogger implements ports.Logger with JSON output using zap.
func NewJSONLogger ¶
func NewJSONLogger(path string, level Level) (*JSONLogger, error)
NewJSONLogger creates a JSON logger that writes to a file.
func (*JSONLogger) Debug ¶
func (l *JSONLogger) Debug(msg string, fields ...any)
func (*JSONLogger) Error ¶
func (l *JSONLogger) Error(msg string, fields ...any)
func (*JSONLogger) Info ¶
func (l *JSONLogger) Info(msg string, fields ...any)
func (*JSONLogger) Warn ¶
func (l *JSONLogger) Warn(msg string, fields ...any)
func (*JSONLogger) WithContext ¶
func (l *JSONLogger) WithContext(ctx map[string]any) ports.Logger
type MultiLogger ¶
type MultiLogger struct {
// contains filtered or unexported fields
}
MultiLogger delegates log calls to multiple loggers.
func NewMultiLogger ¶
func NewMultiLogger(loggers ...ports.Logger) *MultiLogger
NewMultiLogger creates a logger that writes to all provided loggers.
func (*MultiLogger) Debug ¶
func (m *MultiLogger) Debug(msg string, fields ...any)
func (*MultiLogger) Error ¶
func (m *MultiLogger) Error(msg string, fields ...any)
func (*MultiLogger) Info ¶
func (m *MultiLogger) Info(msg string, fields ...any)
func (*MultiLogger) Warn ¶
func (m *MultiLogger) Warn(msg string, fields ...any)
func (*MultiLogger) WithContext ¶
func (m *MultiLogger) WithContext(ctx map[string]any) ports.Logger
type SecretMasker ¶
type SecretMasker struct {
// contains filtered or unexported fields
}
SecretMasker masks sensitive values in log fields.
func NewSecretMasker ¶
func NewSecretMasker(additionalPatterns ...string) *SecretMasker
NewSecretMasker creates a masker with default patterns plus any additional ones.
func (*SecretMasker) IsSecretKey ¶
func (m *SecretMasker) IsSecretKey(key string) bool
IsSecretKey checks if a key matches any secret pattern.
func (*SecretMasker) MaskFields ¶
func (m *SecretMasker) MaskFields(fields []any) []any
MaskFields replaces values of secret keys with "***". Fields are expected as key-value pairs: key1, val1, key2, val2...