Documentation
¶
Overview ¶
Package logging provides shared logging utilities for gridctl.
Package logging provides shared logging utilities for gridctl.
Package logging provides shared logging utilities for gridctl.
Index ¶
- func Caller(depth int) (file string, line int)
- func NewDiscardLogger() *slog.Logger
- func NewStructuredLogger(cfg Config) *slog.Logger
- func ParseLevel(level string) slog.Level
- func RedactEnv(env map[string]string) map[string]string
- func RedactString(s string) string
- func WithComponent(logger *slog.Logger, component string) *slog.Logger
- func WithTraceID(logger *slog.Logger, traceID string) *slog.Logger
- type BufferHandler
- type BufferedEntry
- type Config
- type DiscardHandler
- type LogBuffer
- type LogEntry
- type LogFormat
- type RedactingHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Caller ¶
Caller returns the file and line of the caller at the given depth. Useful for adding source information to logs.
func NewDiscardLogger ¶
NewDiscardLogger returns a logger that discards all output. This is useful as a default logger when no logging is configured.
func NewStructuredLogger ¶
NewStructuredLogger creates a new structured logger with the given configuration.
func ParseLevel ¶
ParseLevel converts a string level to slog.Level.
func RedactEnv ¶
RedactEnv returns a copy of the env map with sensitive values redacted. Keys matching common secret patterns have their values replaced with [REDACTED].
func RedactString ¶
RedactString applies the default redaction patterns to a string. Use this for redacting secrets in non-slog output (e.g., verbose JSON dumps).
func WithComponent ¶
WithComponent returns a new logger with the given component name.
Types ¶
type BufferHandler ¶
type BufferHandler struct {
// contains filtered or unexported fields
}
BufferHandler is a slog.Handler that writes to both a LogBuffer and an underlying handler.
func NewBufferHandler ¶
func NewBufferHandler(buffer *LogBuffer, inner slog.Handler) *BufferHandler
NewBufferHandler creates a handler that writes to both a buffer and another handler. If inner is nil, only the buffer receives logs.
func (*BufferHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level.
type BufferedEntry ¶
type BufferedEntry struct {
Level string `json:"level"`
Timestamp string `json:"ts"`
Message string `json:"msg"`
Component string `json:"component,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Attrs map[string]any `json:"attrs,omitempty"`
}
BufferedEntry represents a log entry stored in the buffer.
type Config ¶
type Config struct {
// Level sets the minimum log level (default: INFO).
Level slog.Level
// Format sets the output format (default: JSON).
Format LogFormat
// Output sets the writer for log output (default: os.Stderr).
Output io.Writer
// AddSource adds source file and line information to logs.
AddSource bool
// Component identifies the logging component (e.g., "gateway", "orchestrator").
Component string
}
Config holds configuration for structured logging.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default logging configuration.
type DiscardHandler ¶
type DiscardHandler struct{}
DiscardHandler is a slog.Handler that discards all log records. Use this to create a no-op logger: slog.New(logging.DiscardHandler{})
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
LogBuffer stores recent log entries in memory for retrieval via API.
func NewLogBuffer ¶
NewLogBuffer creates a new log buffer with the specified maximum size.
func (*LogBuffer) Add ¶
func (b *LogBuffer) Add(entry BufferedEntry)
Add adds a new entry to the buffer.
func (*LogBuffer) GetRecent ¶
func (b *LogBuffer) GetRecent(n int) []BufferedEntry
GetRecent returns the most recent n entries.
type LogEntry ¶
type LogEntry struct {
Level string `json:"level"`
Timestamp string `json:"ts"`
Message string `json:"msg"`
Component string `json:"component,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Logger string `json:"logger,omitempty"`
Meta map[string]any `json:"meta,omitempty"`
}
LogEntry represents a structured log entry for frontend consumption. This is the schema that the frontend expects when parsing logs.
type LogFormat ¶
type LogFormat string
LogFormat specifies the output format for structured logging.
func ParseFormat ¶
ParseFormat converts a string format to LogFormat.
type RedactingHandler ¶
type RedactingHandler struct {
// contains filtered or unexported fields
}
RedactingHandler is a slog.Handler that redacts sensitive values from all log records before forwarding them to an inner handler. It scans string values in the log message and all attributes for patterns that look like secrets (bearer tokens, authorization headers, passwords, API keys).
func NewRedactingHandler ¶
func NewRedactingHandler(inner slog.Handler) *RedactingHandler
NewRedactingHandler wraps an inner handler with secret redaction.