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 ¶
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 LogRequest ¶
LogRequest logs a JSON-RPC request at Debug level.
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 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.
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.