Documentation
¶
Index ¶
- func Initialize(config Config) error
- func IsCredentialHeader(name string) bool
- func LogWebSocketConnection(event string, sessionID, userID, diagramID string, ...)
- func LogWebSocketError(errorType, errorMessage, sessionID, userID string, ...)
- func LogWebSocketMessage(direction WSMessageDirection, sessionID, userID string, messageType string, ...)
- func LogWebSocketMetrics(sessionID string, metrics map[string]any)
- func LoggerMiddleware() gin.HandlerFunc
- func NewRedactionHandler(handler slog.Handler, config RedactionConfig) (slog.Handler, error)
- func PerformanceMiddleware(slowRequestThreshold time.Duration) gin.HandlerFunc
- func Recoverer() gin.HandlerFunc
- func RedactHeaders(headers map[string][]string) map[string][]string
- func RedactSensitiveInfo(input string) string
- func RedactWebSocketMessage(message string) string
- func RequestResponseLogger(config RequestResponseLoggingConfig) gin.HandlerFunc
- func SanitizeLogMessage(message string) string
- func StructuredLogHandler() gin.HandlerFunc
- type CloudLogHandler
- func (h *CloudLogHandler) Close() error
- func (h *CloudLogHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *CloudLogHandler) ErrorCount() int64
- func (h *CloudLogHandler) Handle(ctx context.Context, record slog.Record) error
- func (h *CloudLogHandler) LastError() error
- func (h *CloudLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *CloudLogHandler) WithGroup(name string) slog.Handler
- type CloudLogHandlerConfig
- type CloudLogWriter
- type Config
- type ContextLogger
- func (cl *ContextLogger) Debug(format string, args ...any)
- func (cl *ContextLogger) DebugCtx(msg string, attrs ...slog.Attr)
- func (cl *ContextLogger) Error(format string, args ...any)
- func (cl *ContextLogger) ErrorCtx(msg string, attrs ...slog.Attr)
- func (cl *ContextLogger) GetSlogger() *slog.Logger
- func (cl *ContextLogger) Info(format string, args ...any)
- func (cl *ContextLogger) InfoCtx(msg string, attrs ...slog.Attr)
- func (cl *ContextLogger) Warn(format string, args ...any)
- func (cl *ContextLogger) WarnCtx(msg string, attrs ...slog.Attr)
- func (cl *ContextLogger) WithAttrs(attrs ...slog.Attr) *ContextLogger
- func (cl *ContextLogger) WithGroup(name string) *ContextLogger
- type FallbackLogger
- type GinContextLike
- type LogEntry
- type LogLevel
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) CloudLogErrors() int64
- func (l *Logger) CloudLogLastError() error
- func (l *Logger) Debug(format string, args ...any)
- func (l *Logger) DebugCtx(ctx context.Context, msg string, attrs ...slog.Attr)
- func (l *Logger) Error(format string, args ...any)
- func (l *Logger) ErrorCtx(ctx context.Context, msg string, attrs ...slog.Attr)
- func (l *Logger) GetSlogger() *slog.Logger
- func (l *Logger) Info(format string, args ...any)
- func (l *Logger) InfoCtx(ctx context.Context, msg string, attrs ...slog.Attr)
- func (l *Logger) Warn(format string, args ...any)
- func (l *Logger) WarnCtx(ctx context.Context, msg string, attrs ...slog.Attr)
- func (l *Logger) WithContext(c GinContextLike) *ContextLogger
- type NoopCloudWriter
- func (n *NoopCloudWriter) Close() error
- func (n *NoopCloudWriter) Flush(_ context.Context) error
- func (n *NoopCloudWriter) IsHealthy(_ context.Context) bool
- func (n *NoopCloudWriter) Name() string
- func (n *NoopCloudWriter) Write(p []byte) (int, error)
- func (n *NoopCloudWriter) WriteLog(_ context.Context, _ LogEntry) error
- type RedactionAction
- type RedactionConfig
- type RedactionRule
- type RequestResponseLoggingConfig
- type SimpleLogger
- type WSMessageDirection
- type WebSocketDebugLogger
- func (wsl *WebSocketDebugLogger) ClearAllSessions()
- func (wsl *WebSocketDebugLogger) DisableAllSessions()
- func (wsl *WebSocketDebugLogger) DisableSessionLogging(sessionID string)
- func (wsl *WebSocketDebugLogger) EnableSessionLogging(sessionID string)
- func (wsl *WebSocketDebugLogger) GetEnabledSessions() []string
- func (wsl *WebSocketDebugLogger) IsSessionLoggingEnabled(sessionID string) bool
- func (wsl *WebSocketDebugLogger) LogMessage(sessionID, userID, direction string, message []byte)
- type WebSocketLoggingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCredentialHeader ¶ added in v1.21.30
IsCredentialHeader reports whether a header's value is a credential.
func LogWebSocketConnection ¶
func LogWebSocketConnection(event string, sessionID, userID, diagramID string, config WebSocketLoggingConfig)
LogWebSocketConnection logs WebSocket connection events (compatibility with original signature)
func LogWebSocketError ¶
func LogWebSocketError(errorType, errorMessage, sessionID, userID string, config WebSocketLoggingConfig)
LogWebSocketError logs WebSocket-related errors (compatibility with original signature)
func LogWebSocketMessage ¶
func LogWebSocketMessage(direction WSMessageDirection, sessionID, userID string, messageType string, data []byte, config WebSocketLoggingConfig)
LogWebSocketMessage logs WebSocket messages with optional token redaction
func LogWebSocketMetrics ¶
LogWebSocketMetrics logs WebSocket performance metrics
func LoggerMiddleware ¶
func LoggerMiddleware() gin.HandlerFunc
LoggerMiddleware returns a Gin middleware for logging requests using slog
func NewRedactionHandler ¶
NewRedactionHandler creates a new redaction handler
func PerformanceMiddleware ¶
func PerformanceMiddleware(slowRequestThreshold time.Duration) gin.HandlerFunc
PerformanceMiddleware logs performance metrics for requests
func Recoverer ¶
func Recoverer() gin.HandlerFunc
Recoverer creates middleware for recovering from panics using slog
func RedactHeaders ¶
RedactHeaders creates a copy of headers map with sensitive values redacted
func RedactSensitiveInfo ¶
RedactSensitiveInfo removes or masks sensitive information from strings (legacy compatibility)
func RedactWebSocketMessage ¶
RedactWebSocketMessage applies redaction rules to WebSocket message content
func RequestResponseLogger ¶
func RequestResponseLogger(config RequestResponseLoggingConfig) gin.HandlerFunc
RequestResponseLogger creates middleware for detailed request/response logging
func SanitizeLogMessage ¶
SanitizeLogMessage removes newlines and other control characters from log messages
func StructuredLogHandler ¶
func StructuredLogHandler() gin.HandlerFunc
StructuredLogHandler provides a Gin handler for structured logging endpoints
Types ¶
type CloudLogHandler ¶
type CloudLogHandler struct {
// contains filtered or unexported fields
}
CloudLogHandler is a slog.Handler that writes to cloud logging providers. It wraps another handler for local logging and adds cloud logging on top.
func NewCloudLogHandler ¶
func NewCloudLogHandler(config CloudLogHandlerConfig) *CloudLogHandler
NewCloudLogHandler creates a new handler that writes to both local and cloud.
func (*CloudLogHandler) Close ¶
func (h *CloudLogHandler) Close() error
Close shuts down the handler and flushes remaining logs.
func (*CloudLogHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level.
func (*CloudLogHandler) ErrorCount ¶
func (h *CloudLogHandler) ErrorCount() int64
ErrorCount returns the total number of cloud write errors.
func (*CloudLogHandler) LastError ¶
func (h *CloudLogHandler) LastError() error
LastError returns the last cloud write error, if any.
type CloudLogHandlerConfig ¶
type CloudLogHandlerConfig struct {
// LocalHandler is the handler for local logging (required)
LocalHandler slog.Handler
// CloudWriter is the cloud logging provider (required)
CloudWriter CloudLogWriter
// Level is the minimum log level for cloud logging
Level slog.Level
// BufferSize is the size of the async write buffer (default: 1000)
BufferSize int
// AsyncWrites enables asynchronous cloud writes (default: true)
AsyncWrites bool
}
CloudLogHandlerConfig configures the CloudLogHandler.
type CloudLogWriter ¶
type CloudLogWriter interface {
io.Writer
// WriteLog sends a structured log entry to the cloud provider.
// This is the preferred method for cloud logging as it preserves structure.
WriteLog(ctx context.Context, entry LogEntry) error
// Flush forces any buffered logs to be sent immediately.
Flush(ctx context.Context) error
// Close releases resources and flushes any remaining logs.
Close() error
// Name returns the provider name for identification.
Name() string
// IsHealthy returns true if the cloud provider is reachable.
IsHealthy(ctx context.Context) bool
}
CloudLogWriter defines the interface for cloud logging providers. Implementations should handle buffering, batching, and retry logic internally.
type Config ¶
type Config struct {
// Level is the minimum log level to output
Level LogLevel
// IsDev indicates if this is a development build (includes file/line info)
IsDev bool
// LogDir is the directory to store log files
LogDir string
// MaxAgeDays is the maximum number of days to retain logs
MaxAgeDays int
// MaxSizeMB is the maximum size of a log file in MB before rotation
MaxSizeMB int
// MaxBackups is the maximum number of old log files to retain
MaxBackups int
// AlsoLogToConsole controls if logs also go to stdout/stderr
AlsoLogToConsole bool
// SuppressUnauthenticatedLogs controls whether to log requests without authenticated users
SuppressUnauthenticatedLogs bool
// RedactionConfig controls sensitive data redaction (optional, uses defaults if nil)
RedactionConfig *RedactionConfig
// Cloud logging configuration (all optional)
// CloudWriter is the cloud logging provider (nil to disable cloud logging)
CloudWriter CloudLogWriter
// CloudLogLevel is the minimum level for cloud logging (defaults to Level if not set)
CloudLogLevel *LogLevel
// CloudLogBufferSize is the buffer size for async cloud writes (default: 1000)
CloudLogBufferSize int
// CloudErrorThreshold is the number of consecutive cloud-sink write
// failures (observed at 60-second poll intervals) before a single Warn
// entry is emitted. The counter resets on a quiet poll. Set to 0 to
// disable the alarm. A negative value selects the default of 5
// (used when this Config is built without a YAML-supplied value).
CloudErrorThreshold int
}
Config holds configuration options for the logger (maintained for compatibility)
type ContextLogger ¶
type ContextLogger struct {
// contains filtered or unexported fields
}
ContextLogger adds request context to log messages All messages are sanitized to prevent log injection attacks (CWE-117)
func (*ContextLogger) Debug ¶
func (cl *ContextLogger) Debug(format string, args ...any)
Debug logs a debug-level message with context (compatibility method)
func (*ContextLogger) DebugCtx ¶
func (cl *ContextLogger) DebugCtx(msg string, attrs ...slog.Attr)
DebugCtx logs a debug message with additional structured attributes
func (*ContextLogger) Error ¶
func (cl *ContextLogger) Error(format string, args ...any)
Error logs an error-level message with context (compatibility method)
func (*ContextLogger) ErrorCtx ¶
func (cl *ContextLogger) ErrorCtx(msg string, attrs ...slog.Attr)
ErrorCtx logs an error message with additional structured attributes
func (*ContextLogger) GetSlogger ¶
func (cl *ContextLogger) GetSlogger() *slog.Logger
GetSlogger returns the underlying slog.Logger for this context
func (*ContextLogger) Info ¶
func (cl *ContextLogger) Info(format string, args ...any)
Info logs an info-level message with context (compatibility method)
func (*ContextLogger) InfoCtx ¶
func (cl *ContextLogger) InfoCtx(msg string, attrs ...slog.Attr)
InfoCtx logs an info message with additional structured attributes
func (*ContextLogger) Warn ¶
func (cl *ContextLogger) Warn(format string, args ...any)
Warn logs a warning-level message with context (compatibility method)
func (*ContextLogger) WarnCtx ¶
func (cl *ContextLogger) WarnCtx(msg string, attrs ...slog.Attr)
WarnCtx logs a warning message with additional structured attributes
func (*ContextLogger) WithAttrs ¶
func (cl *ContextLogger) WithAttrs(attrs ...slog.Attr) *ContextLogger
WithAttrs returns a new ContextLogger with additional attributes
func (*ContextLogger) WithGroup ¶
func (cl *ContextLogger) WithGroup(name string) *ContextLogger
WithGroup returns a new ContextLogger with a group name
type FallbackLogger ¶
type FallbackLogger struct {
// contains filtered or unexported fields
}
FallbackLogger provides a simple logger that writes to gin's output (compatibility) All messages are sanitized to prevent log injection attacks (CWE-117)
func (*FallbackLogger) Debug ¶
func (l *FallbackLogger) Debug(format string, args ...any)
Debug logs debug level messages
func (*FallbackLogger) Error ¶
func (l *FallbackLogger) Error(format string, args ...any)
Error logs error level messages
func (*FallbackLogger) Info ¶
func (l *FallbackLogger) Info(format string, args ...any)
Info logs info level messages
func (*FallbackLogger) Warn ¶
func (l *FallbackLogger) Warn(format string, args ...any)
Warn logs warning level messages
type GinContextLike ¶
type GinContextLike interface {
Get(key any) (any, bool)
GetHeader(key string) string
ClientIP() string
}
GinContextLike defines a minimal interface for contexts that can be used with the logger
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time
Level slog.Level
Message string
Attrs map[string]any
Source string // file:line if available
}
LogEntry represents a structured log entry for cloud providers.
type LogLevel ¶
type LogLevel int
LogLevel represents logging verbosity (maintained for compatibility)
func ParseLogLevel ¶
ParseLogLevel converts a string log level to LogLevel
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the slog-based logging component
func Get ¶
func Get() *Logger
Get returns the global logger instance, initializing with defaults if needed
func (*Logger) CloudLogErrors ¶
CloudLogErrors returns the count of cloud logging errors.
func (*Logger) CloudLogLastError ¶
CloudLogLastError returns the last cloud logging error, if any.
func (*Logger) Debug ¶
Debug logs a debug-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117)
func (*Logger) Error ¶
Error logs an error-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117)
func (*Logger) GetSlogger ¶
GetSlogger returns the underlying slog.Logger for advanced usage
func (*Logger) Info ¶
Info logs an info-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117)
func (*Logger) Warn ¶
Warn logs a warning-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117)
func (*Logger) WithContext ¶
func (l *Logger) WithContext(c GinContextLike) *ContextLogger
WithContext returns a context-aware logger that includes request information
type NoopCloudWriter ¶
type NoopCloudWriter struct{}
NoopCloudWriter is a no-op implementation for testing or when cloud logging is disabled.
func (*NoopCloudWriter) Close ¶
func (n *NoopCloudWriter) Close() error
func (*NoopCloudWriter) Name ¶
func (n *NoopCloudWriter) Name() string
type RedactionAction ¶
type RedactionAction string
RedactionAction defines how sensitive data should be handled
const ( // RedactionOmit removes the field entirely from logs RedactionOmit RedactionAction = "omit" // RedactionObfuscate replaces the value with [REDACTED] RedactionObfuscate RedactionAction = "obfuscate" // RedactionPartial shows first and last few characters with middle redacted RedactionPartial RedactionAction = "partial" )
type RedactionConfig ¶
type RedactionConfig struct {
// Enabled controls whether redaction is active
Enabled bool `yaml:"enabled" json:"enabled"`
// Rules contains all redaction rules
Rules []RedactionRule `yaml:"rules" json:"rules"`
}
RedactionConfig holds all redaction rules
func DefaultRedactionConfig ¶
func DefaultRedactionConfig() RedactionConfig
DefaultRedactionConfig provides sensible defaults for security
func (*RedactionConfig) CompileRules ¶
func (rc *RedactionConfig) CompileRules() error
CompileRules compiles regex patterns for all rules
type RedactionRule ¶
type RedactionRule struct {
// FieldPattern is a regex pattern to match field names
FieldPattern string `yaml:"field_pattern" json:"field_pattern"`
// Action specifies what to do with matching fields
Action RedactionAction `yaml:"action" json:"action"`
// LogLevels specifies which log levels this rule applies to (empty = all levels)
LogLevels []string `yaml:"log_levels,omitempty" json:"log_levels,omitempty"`
// Groups specifies which log groups this rule applies to (empty = all groups)
Groups []string `yaml:"groups,omitempty" json:"groups,omitempty"`
// contains filtered or unexported fields
}
RedactionRule defines a single redaction rule
type RequestResponseLoggingConfig ¶
type RequestResponseLoggingConfig struct {
LogRequests bool
LogResponses bool
RedactTokens bool
MaxBodySize int64 // Max request/response body size to log (in bytes)
SkipPaths []string
OnlyDebugLevel bool // Only log at debug level
}
RequestResponseLoggingConfig holds configuration for enhanced logging
type SimpleLogger ¶
type SimpleLogger interface {
Debug(format string, args ...any)
Info(format string, args ...any)
Warn(format string, args ...any)
Error(format string, args ...any)
}
SimpleLogger defines the basic logging interface used across the app (compatibility)
func GetContextLogger ¶
func GetContextLogger(c GinContextLike) SimpleLogger
GetContextLogger retrieves a logger from the context or creates a fallback
func NewFallbackLogger ¶
func NewFallbackLogger() SimpleLogger
NewFallbackLogger creates a simple logger for fallback use
type WSMessageDirection ¶
type WSMessageDirection string
WSMessageDirection indicates the direction of the WebSocket message
const ( WSMessageInbound WSMessageDirection = "INBOUND" WSMessageOutbound WSMessageDirection = "OUTBOUND" )
type WebSocketDebugLogger ¶
type WebSocketDebugLogger struct {
// contains filtered or unexported fields
}
WebSocketDebugLogger provides toggleable WebSocket message logging for debugging
func GetWebSocketDebugLogger ¶
func GetWebSocketDebugLogger() *WebSocketDebugLogger
GetWebSocketDebugLogger returns the global WebSocket debug logger
func NewWebSocketDebugLogger ¶
func NewWebSocketDebugLogger(logger *Logger) *WebSocketDebugLogger
NewWebSocketDebugLogger creates a new WebSocket debug logger
func (*WebSocketDebugLogger) ClearAllSessions ¶
func (wsl *WebSocketDebugLogger) ClearAllSessions()
ClearAllSessions is an alias for DisableAllSessions (compatibility)
func (*WebSocketDebugLogger) DisableAllSessions ¶
func (wsl *WebSocketDebugLogger) DisableAllSessions()
DisableAllSessions disables debug logging for all sessions
func (*WebSocketDebugLogger) DisableSessionLogging ¶
func (wsl *WebSocketDebugLogger) DisableSessionLogging(sessionID string)
DisableSessionLogging disables debug logging for a specific session
func (*WebSocketDebugLogger) EnableSessionLogging ¶
func (wsl *WebSocketDebugLogger) EnableSessionLogging(sessionID string)
EnableSessionLogging enables debug logging for a specific session
func (*WebSocketDebugLogger) GetEnabledSessions ¶
func (wsl *WebSocketDebugLogger) GetEnabledSessions() []string
GetEnabledSessions returns a list of sessions with debug logging enabled
func (*WebSocketDebugLogger) IsSessionLoggingEnabled ¶
func (wsl *WebSocketDebugLogger) IsSessionLoggingEnabled(sessionID string) bool
IsSessionLoggingEnabled checks if logging is enabled for a session
func (*WebSocketDebugLogger) LogMessage ¶
func (wsl *WebSocketDebugLogger) LogMessage(sessionID, userID, direction string, message []byte)
LogMessage logs a WebSocket message if debug logging is enabled for the session