Documentation
¶
Overview ¶
Package logging provides file-based structured logging for diagnostics. Logs are written as JSON lines to ~/.dws/logs/dws.log with automatic size-based rotation. Sensitive values (tokens, secrets) are never logged.
Index ¶
- func IsSensitiveKey(key string) bool
- func LogCommandEnd(logger *slog.Logger, executionId, product, tool string, success bool, ...)
- func LogCommandStart(logger *slog.Logger, executionId, command, product, tool, version string, ...)
- func LogErrorClassified(logger *slog.Logger, method, executionId, category, reason string, ...)
- func LogRequest(logger *slog.Logger, method, endpoint, executionId string, bodySize int)
- func LogRequestBody(logger *slog.Logger, method, executionId string, toolName string, ...)
- func LogResponse(logger *slog.Logger, method, endpoint string, statusCode int, respSize int, ...)
- func LogResponseBody(logger *slog.Logger, method, executionId string, statusCode int, body []byte, ...)
- func LogRetryAttempt(logger *slog.Logger, method, executionId string, attempt, maxRetries int, ...)
- func RedactHeaders(headers http.Header) []slog.Attr
- func RedactValue(value string) string
- func SanitizeArguments(args map[string]any, maxBytes int) string
- func TruncateBody(body []byte, maxBytes int) string
- type FileLogger
- type MultiHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSensitiveKey ¶
IsSensitiveKey returns true if the key (case-insensitive) refers to a credential or secret that must not appear in log files.
func LogCommandEnd ¶ added in v1.0.5
func LogCommandEnd(logger *slog.Logger, executionId, product, tool string, success bool, duration time.Duration, errCategory, errReason string)
LogCommandEnd logs the end of a command execution.
func LogCommandStart ¶ added in v1.0.5
func LogCommandStart(logger *slog.Logger, executionId, command, product, tool, version string, authPresent bool)
LogCommandStart logs the beginning of a command execution.
func LogErrorClassified ¶ added in v1.0.5
func LogErrorClassified(logger *slog.Logger, method, executionId, category, reason string, httpStatus, rpcCode int, retryable bool, traceID string)
LogErrorClassified logs the final error classification at Warn level.
func LogRequest ¶
LogRequest logs a JSON-RPC request at Debug level.
func LogRequestBody ¶ added in v1.0.5
func LogRequestBody(logger *slog.Logger, method, executionId string, toolName string, arguments map[string]any)
LogRequestBody logs a truncated, redacted request body for tools/call.
func LogResponse ¶
func LogResponse(logger *slog.Logger, method, endpoint string, statusCode int, respSize int, duration time.Duration, err error)
LogResponse logs a JSON-RPC response at Debug level.
func LogResponseBody ¶ added in v1.0.5
func LogResponseBody(logger *slog.Logger, method, executionId string, statusCode int, body []byte, traceID string)
LogResponseBody logs a truncated response body on error paths.
func LogRetryAttempt ¶ added in v1.0.5
func LogRetryAttempt(logger *slog.Logger, method, executionId string, attempt, maxRetries int, statusCode int, delay time.Duration, lastErr error)
LogRetryAttempt logs a retry attempt at Warn level.
func RedactHeaders ¶ added in v1.0.5
RedactHeaders returns slog attributes for HTTP headers with sensitive values redacted.
func RedactValue ¶
RedactValue replaces a sensitive value with a safe placeholder. It preserves the first 4 characters for identification if the value is long enough, otherwise fully redacts.
func SanitizeArguments ¶ added in v1.0.5
SanitizeArguments returns a JSON string of the arguments map with sensitive-looking values replaced by "***". Truncates to maxBytes.
func TruncateBody ¶ added in v1.0.5
TruncateBody returns the body truncated to maxBytes with a UTF-8 safe boundary. If truncated, appends a marker showing the original size.
Types ¶
type FileLogger ¶
FileLogger wraps a rotatingWriter and provides a structured slog.Logger that writes JSON lines to disk.
func Setup ¶
func Setup(configDir string) *FileLogger
Setup creates the log directory and returns a FileLogger. If directory creation fails, it returns a no-op logger that discards all output.
func (*FileLogger) Close ¶
func (fl *FileLogger) Close() error
Close flushes and closes the underlying log file.
func (*FileLogger) Writer ¶
func (fl *FileLogger) Writer() io.Writer
Writer returns the underlying io.Writer for use with slog handlers. Returns io.Discard if the logger is not initialized.
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}
MultiHandler fans out slog records to multiple handlers. Each handler applies its own level filter independently.
func NewMultiHandler ¶
func NewMultiHandler(handlers ...slog.Handler) *MultiHandler
NewMultiHandler creates a handler that writes to all provided handlers.