logging

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

func IsSensitiveKey(key string) bool

IsSensitiveKey returns true if the key (case-insensitive) refers to a credential or secret that must not appear in log files.

func LogRequest

func LogRequest(logger *slog.Logger, method, endpoint, executionId string, bodySize int)

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

func RedactValue(value string) string

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

type FileLogger struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

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.

func (*MultiHandler) Enabled

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

func (*MultiHandler) Handle

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

func (*MultiHandler) WithAttrs

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

func (*MultiHandler) WithGroup

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

Jump to

Keyboard shortcuts

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