slogging

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(config Config) error

Initialize sets up the global logger SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a Logger from config and store it as the global logger instance (mutates shared state)

func LogWebSocketConnection

func LogWebSocketConnection(event string, sessionID, userID, diagramID string, config WebSocketLoggingConfig)

LogWebSocketConnection logs WebSocket connection events (compatibility with original signature) SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: log a WebSocket connection lifecycle event with session, user, and diagram identifiers (pure)

func LogWebSocketError

func LogWebSocketError(errorType, errorMessage, sessionID, userID string, config WebSocketLoggingConfig)

LogWebSocketError logs WebSocket-related errors (compatibility with original signature) SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: log a WebSocket error with type, message, session, and user context (pure)

func LogWebSocketMessage

func LogWebSocketMessage(direction WSMessageDirection, sessionID, userID string, messageType string, data []byte, config WebSocketLoggingConfig)

LogWebSocketMessage logs WebSocket messages with optional token redaction SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: log a WebSocket message at debug level with optional token redaction and size enforcement (pure)

func LogWebSocketMetrics

func LogWebSocketMetrics(sessionID string, metrics map[string]any)

LogWebSocketMetrics logs WebSocket performance metrics SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: log WebSocket performance metrics for a session at debug level (pure)

func LoggerMiddleware

func LoggerMiddleware() gin.HandlerFunc

LoggerMiddleware returns a Gin middleware for logging requests using slog SEM@3e48a58cb418d2e7a4f04f1288fa11cb942bc99e: log each HTTP request's start, completion, and status at the appropriate level

func NewRedactionHandler

func NewRedactionHandler(handler slog.Handler, config RedactionConfig) (slog.Handler, error)

NewRedactionHandler creates a new redaction handler SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a redacting slog.Handler by compiling rules and wrapping an existing handler (pure)

func PerformanceMiddleware

func PerformanceMiddleware(slowRequestThreshold time.Duration) gin.HandlerFunc

PerformanceMiddleware logs performance metrics for requests SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: warn when a request exceeds a configurable slow-request duration threshold

func Recoverer

func Recoverer() gin.HandlerFunc

Recoverer creates middleware for recovering from panics using slog SEM@a1d7f44f9fbf44b654abfc81c5b3770eb540ecb0: catch panics in downstream handlers and return 500 with a structured stack trace

func RedactHeaders

func RedactHeaders(headers map[string][]string) map[string][]string

RedactHeaders creates a copy of headers map with sensitive values redacted SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a copy of an HTTP headers map with sensitive header values partially redacted (pure)

func RedactSensitiveInfo

func RedactSensitiveInfo(input string) string

RedactSensitiveInfo removes or masks sensitive information from strings (legacy compatibility) SEM@9745b416c50726fc3ca5d4637364ba55d6ba0699: apply default redaction rules to a raw string value (pure)

func RedactWebSocketMessage

func RedactWebSocketMessage(message string) string

RedactWebSocketMessage applies redaction rules to WebSocket message content SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: redact sensitive fields from a WebSocket message string, parsing as JSON when possible (pure)

func RequestResponseLogger

func RequestResponseLogger(config RequestResponseLoggingConfig) gin.HandlerFunc

RequestResponseLogger creates middleware for detailed request/response logging SEM@3e48a58cb418d2e7a4f04f1288fa11cb942bc99e: build a Gin middleware that logs structured HTTP request and response details per config

func RequestTracingMiddleware

func RequestTracingMiddleware(enableBodyLogging bool) gin.HandlerFunc

RequestTracingMiddleware adds detailed request tracing for debugging SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: log detailed request headers, URL, and query params at debug level

func SanitizeLogMessage

func SanitizeLogMessage(message string) string

SanitizeLogMessage removes newlines and other control characters from log messages SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: strip control characters and collapse whitespace in a log message string (pure)

func StructuredLogHandler

func StructuredLogHandler() gin.HandlerFunc

StructuredLogHandler provides a Gin handler for structured logging endpoints SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: handle an HTTP log ingestion endpoint and emit structured log entries at the requested level

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. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: slog handler that fans out to a local handler and an async cloud logging provider

func NewCloudLogHandler

func NewCloudLogHandler(config CloudLogHandlerConfig) *CloudLogHandler

NewCloudLogHandler creates a new handler that writes to both local and cloud. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: build a CloudLogHandler with async writer goroutine and configurable buffer (mutates shared state)

func (*CloudLogHandler) Close

func (h *CloudLogHandler) Close() error

Close shuts down the handler and flushes remaining logs. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: flush remaining buffered log entries and shut down the cloud handler (mutates shared state)

func (*CloudLogHandler) Enabled

func (h *CloudLogHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: report whether the handler accepts records at the given log level (pure)

func (*CloudLogHandler) ErrorCount

func (h *CloudLogHandler) ErrorCount() int64

ErrorCount returns the total number of cloud write errors. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: return the total number of cloud write errors accumulated since start (pure)

func (*CloudLogHandler) Handle

func (h *CloudLogHandler) Handle(ctx context.Context, record slog.Record) error

Handle handles the Record. SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: dispatch a log record to local and cloud handlers, buffering cloud delivery asynchronously

func (*CloudLogHandler) LastError

func (h *CloudLogHandler) LastError() error

LastError returns the last cloud write error, if any. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: return the most recent cloud write error, or nil if none (pure)

func (*CloudLogHandler) WithAttrs

func (h *CloudLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new Handler with the given attributes added. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: return a new handler with additional attributes merged into all subsequent log entries (pure)

func (*CloudLogHandler) WithGroup

func (h *CloudLogHandler) WithGroup(name string) slog.Handler

WithGroup returns a new Handler with the given group name. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: return a new handler that namespaces all attribute keys under the given group (pure)

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. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: configuration for CloudLogHandler including local handler, cloud writer, level, and buffer settings

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. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: interface for cloud logging providers supporting structured log delivery and health checks

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) SEM@ab6c8e11db85b002bee1e06e5cddbec70e9e0d70: configuration for logger construction including level, rotation, console, redaction, and cloud settings (pure)

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) SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: request-scoped structured logger enriched with request ID, client IP, user ID, and OTel trace context (pure)

func (*ContextLogger) Debug

func (cl *ContextLogger) Debug(format string, args ...any)

Debug logs a debug-level message with context (compatibility method) SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized debug message with request context (pure)

func (*ContextLogger) DebugCtx

func (cl *ContextLogger) DebugCtx(msg string, attrs ...slog.Attr)

DebugCtx logs a debug message with additional structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a debug message with structured slog attributes via the request context (pure)

func (*ContextLogger) Error

func (cl *ContextLogger) Error(format string, args ...any)

Error logs an error-level message with context (compatibility method) SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized error message with request context (pure)

func (*ContextLogger) ErrorCtx

func (cl *ContextLogger) ErrorCtx(msg string, attrs ...slog.Attr)

ErrorCtx logs an error message with additional structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log an error message with structured slog attributes via the request context (pure)

func (*ContextLogger) GetSlogger

func (cl *ContextLogger) GetSlogger() *slog.Logger

GetSlogger returns the underlying slog.Logger for this context SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: return the underlying slog.Logger for direct structured logging (pure)

func (*ContextLogger) Info

func (cl *ContextLogger) Info(format string, args ...any)

Info logs an info-level message with context (compatibility method) SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized info message with request context (pure)

func (*ContextLogger) InfoCtx

func (cl *ContextLogger) InfoCtx(msg string, attrs ...slog.Attr)

InfoCtx logs an info message with additional structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log an info message with structured slog attributes via the request context (pure)

func (*ContextLogger) Warn

func (cl *ContextLogger) Warn(format string, args ...any)

Warn logs a warning-level message with context (compatibility method) SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized warning message with request context (pure)

func (*ContextLogger) WarnCtx

func (cl *ContextLogger) WarnCtx(msg string, attrs ...slog.Attr)

WarnCtx logs a warning message with additional structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a warning message with structured slog attributes via the request context (pure)

func (*ContextLogger) WithAttrs

func (cl *ContextLogger) WithAttrs(attrs ...slog.Attr) *ContextLogger

WithAttrs returns a new ContextLogger with additional attributes SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a new ContextLogger with additional structured attributes attached (pure)

func (*ContextLogger) WithGroup

func (cl *ContextLogger) WithGroup(name string) *ContextLogger

WithGroup returns a new ContextLogger with a group name SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a new ContextLogger with all subsequent attributes nested under a group name (pure)

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) SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: simple slog-backed logger used when no request-scoped logger is available (pure)

func (*FallbackLogger) Debug

func (l *FallbackLogger) Debug(format string, args ...any)

Debug logs debug level messages SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized debug message via the fallback logger (pure)

func (*FallbackLogger) Error

func (l *FallbackLogger) Error(format string, args ...any)

Error logs error level messages SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized error message via the fallback logger (pure)

func (*FallbackLogger) Info

func (l *FallbackLogger) Info(format string, args ...any)

Info logs info level messages SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized info message via the fallback logger (pure)

func (*FallbackLogger) Warn

func (l *FallbackLogger) Warn(format string, args ...any)

Warn logs warning level messages SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized warning message via the fallback logger (pure)

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 SEM@c94efddda17fc5e306e3f4ec21ff2fe092472d98: minimal interface for contexts providing header, IP, and key lookup for logger attachment (pure)

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. SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: structured log entry carrying timestamp, level, message, and attributes for cloud providers

type LogLevel

type LogLevel int

LogLevel represents logging verbosity (maintained for compatibility) SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: numeric log severity level used to filter log output (pure)

const (
	// LogLevelDebug includes detailed debug information
	LogLevelDebug LogLevel = iota
	// LogLevelInfo includes general request information
	LogLevelInfo
	// LogLevelWarn includes warnings and errors only
	LogLevelWarn
	// LogLevelError includes only errors
	LogLevelError
)

func ParseLogLevel

func ParseLogLevel(level string) LogLevel

ParseLogLevel converts a string log level to LogLevel SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: parse a log level string to a LogLevel, defaulting to Info on unknown input (pure)

func (LogLevel) String

func (l LogLevel) String() string

String returns the string representation of the log level SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: format a LogLevel as its uppercase name string (pure)

type Logger

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

Logger is the slog-based logging component SEM@ab6c8e11db85b002bee1e06e5cddbec70e9e0d70: structured slog-backed logger with file rotation, redaction, cloud sink, and watchdogs (pure)

func Get

func Get() *Logger

Get returns the global logger instance, initializing with defaults if needed SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: fetch the global Logger, auto-initializing with defaults if not yet set (mutates shared state)

func NewLogger

func NewLogger(config Config) (*Logger, error)

NewLogger creates a new slog-based logger instance SEM@39cf195d9b27ff160d2988b8578ceb31675c7760: build a configured Logger with file rotation, redaction, cloud sink, and watchdogs

func (*Logger) Close

func (l *Logger) Close() error

Close properly closes the logger SEM@ab6c8e11db85b002bee1e06e5cddbec70e9e0d70: flush and close the logger's cloud handler, file logger, and watchdogs

func (*Logger) CloudLogErrors

func (l *Logger) CloudLogErrors() int64

CloudLogErrors returns the count of cloud logging errors. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: fetch the cumulative count of cloud log sink write failures (pure)

func (*Logger) CloudLogLastError

func (l *Logger) CloudLogLastError() error

CloudLogLastError returns the last cloud logging error, if any. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: fetch the most recent cloud log sink error, if any (pure)

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...any)

Debug logs a debug-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117) SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: log a sanitized debug-level message if the level threshold permits (pure)

func (*Logger) DebugCtx

func (l *Logger) DebugCtx(ctx context.Context, msg string, attrs ...slog.Attr)

DebugCtx logs a debug message with context and structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized debug message with structured slog attributes and context (pure)

func (*Logger) Error

func (l *Logger) Error(format string, args ...any)

Error logs an error-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117) SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: log a sanitized error-level message if the level threshold permits (pure)

func (*Logger) ErrorCtx

func (l *Logger) ErrorCtx(ctx context.Context, msg string, attrs ...slog.Attr)

ErrorCtx logs an error message with context and structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized error message with structured slog attributes and context (pure)

func (*Logger) GetSlogger

func (l *Logger) GetSlogger() *slog.Logger

GetSlogger returns the underlying slog.Logger for advanced usage SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: fetch the underlying slog.Logger for advanced structured logging (pure)

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

Info logs an info-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117) SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: log a sanitized info-level message if the level threshold permits (pure)

func (*Logger) InfoCtx

func (l *Logger) InfoCtx(ctx context.Context, msg string, attrs ...slog.Attr)

InfoCtx logs an info message with context and structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized info message with structured slog attributes and context (pure)

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Warn logs a warning-level message (compatibility method) Log messages are sanitized to prevent log injection attacks (CWE-117) SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: log a sanitized warn-level message if the level threshold permits (pure)

func (*Logger) WarnCtx

func (l *Logger) WarnCtx(ctx context.Context, msg string, attrs ...slog.Attr)

WarnCtx logs a warning message with context and structured attributes SEM@b29bc09af9d85dba2a37f84f1ec25c440fb77c3f: log a sanitized warn message with structured slog attributes and context (pure)

func (*Logger) WithContext

func (l *Logger) WithContext(c GinContextLike) *ContextLogger

WithContext returns a context-aware logger that includes request information SEM@3da74faa5e66fc9ead55d176f928fb36713b5ec0: build a ContextLogger bound to request metadata including request ID, client IP, user, and OTel trace (pure)

type NoopCloudWriter

type NoopCloudWriter struct{}

NoopCloudWriter is a no-op implementation for testing or when cloud logging is disabled. SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: no-op CloudLogWriter implementation for testing or when cloud logging is disabled

func (*NoopCloudWriter) Close

func (n *NoopCloudWriter) Close() error

SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: no-op close for the no-op cloud writer (pure)

func (*NoopCloudWriter) Flush

func (n *NoopCloudWriter) Flush(_ context.Context) error

SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: no-op flush for the no-op cloud writer (pure)

func (*NoopCloudWriter) IsHealthy

func (n *NoopCloudWriter) IsHealthy(_ context.Context) bool

SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: report healthy for the no-op cloud writer (pure)

func (*NoopCloudWriter) Name

func (n *NoopCloudWriter) Name() string

SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: return the provider name for the no-op cloud writer (pure)

func (*NoopCloudWriter) Write

func (n *NoopCloudWriter) Write(p []byte) (int, error)

SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: discard bytes and report success for the no-op cloud writer (pure)

func (*NoopCloudWriter) WriteLog

func (n *NoopCloudWriter) WriteLog(_ context.Context, _ LogEntry) error

SEM@24f7dadfcf515c1af48310c466e75a45e19d6e3b: discard a structured log entry for the no-op cloud writer (pure)

type RedactionAction

type RedactionAction string

RedactionAction defines how sensitive data should be handled SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: enumerate the redaction modes: omit, obfuscate, or partially reveal a log field value (pure)

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 SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: hold the enabled flag and ordered list of redaction rules for the log handler (pure)

func DefaultRedactionConfig

func DefaultRedactionConfig() RedactionConfig

DefaultRedactionConfig provides sensible defaults for security SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build the default redaction config masking tokens, secrets, and cookies in structured logs (pure)

func (*RedactionConfig) CompileRules

func (rc *RedactionConfig) CompileRules() error

CompileRules compiles regex patterns for all rules SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: compile all field-pattern regexes in a RedactionConfig; return error on invalid pattern (pure)

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 SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: define a single log-field redaction rule binding a field pattern to an action and scope (pure)

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 SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: configuration controlling which HTTP request and response details to log (pure)

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) SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: minimal interface for printf-style Debug/Info/Warn/Error logging (pure)

func GetContextLogger

func GetContextLogger(c GinContextLike) SimpleLogger

GetContextLogger retrieves a logger from the context or creates a fallback SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: fetch the request-scoped logger from a context or return a fallback logger (pure)

func NewFallbackLogger

func NewFallbackLogger() SimpleLogger

NewFallbackLogger creates a simple logger for fallback use SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a fallback SimpleLogger writing sanitized text to gin's default output (pure)

type WSMessageDirection

type WSMessageDirection string

WSMessageDirection indicates the direction of the WebSocket message SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: enum type distinguishing inbound from outbound WebSocket messages (pure)

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 SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: per-session toggleable debug logger for WebSocket messages (pure)

func GetWebSocketDebugLogger

func GetWebSocketDebugLogger() *WebSocketDebugLogger

GetWebSocketDebugLogger returns the global WebSocket debug logger SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: return the global WebSocket debug logger singleton, initializing it if needed

func NewWebSocketDebugLogger

func NewWebSocketDebugLogger(logger *Logger) *WebSocketDebugLogger

NewWebSocketDebugLogger creates a new WebSocket debug logger SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: build a WebSocket debug logger backed by the given structured logger (pure)

func (*WebSocketDebugLogger) ClearAllSessions

func (wsl *WebSocketDebugLogger) ClearAllSessions()

ClearAllSessions is an alias for DisableAllSessions (compatibility) SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: alias for DisableAllSessions; disable WebSocket debug logging for all sessions (mutates shared state)

func (*WebSocketDebugLogger) DisableAllSessions

func (wsl *WebSocketDebugLogger) DisableAllSessions()

DisableAllSessions disables debug logging for all sessions SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: disable WebSocket debug logging for every active session (mutates shared state)

func (*WebSocketDebugLogger) DisableSessionLogging

func (wsl *WebSocketDebugLogger) DisableSessionLogging(sessionID string)

DisableSessionLogging disables debug logging for a specific session SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: disable WebSocket debug logging for a specific session (mutates shared state)

func (*WebSocketDebugLogger) EnableSessionLogging

func (wsl *WebSocketDebugLogger) EnableSessionLogging(sessionID string)

EnableSessionLogging enables debug logging for a specific session SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: enable WebSocket debug logging for a specific session (mutates shared state)

func (*WebSocketDebugLogger) GetEnabledSessions

func (wsl *WebSocketDebugLogger) GetEnabledSessions() []string

GetEnabledSessions returns a list of sessions with debug logging enabled SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: list all session IDs that currently have WebSocket debug logging enabled (pure)

func (*WebSocketDebugLogger) IsSessionLoggingEnabled

func (wsl *WebSocketDebugLogger) IsSessionLoggingEnabled(sessionID string) bool

IsSessionLoggingEnabled checks if logging is enabled for a session SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: check whether WebSocket debug logging is active for a session (pure)

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 SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: emit a structured WebSocket message log entry if the session has debug logging enabled

type WebSocketLoggingConfig

type WebSocketLoggingConfig struct {
	Enabled        bool
	RedactTokens   bool
	MaxMessageSize int64 // Max message size to log (in bytes)
	OnlyDebugLevel bool  // Only log at debug level
}

WebSocketLoggingConfig holds configuration for WebSocket message logging SEM@fd65443f98d69fa4f22b8f982c98ebf8eb89c515: configuration controlling WebSocket log verbosity, token redaction, and message size limits (pure)

Jump to

Keyboard shortcuts

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