Documentation
¶
Overview ¶
Package logger provides structured logging with subsystem-specific levels and OpenTelemetry trace context integration.
Package logger provides structured logging with subsystem-specific levels and OpenTelemetry trace context integration.
Index ¶
- Constants
- func AddToContext(ctx context.Context, logger *slog.Logger) context.Context
- func FromContext(ctx context.Context) *slog.Logger
- func NewLogger(cfg Config) *slog.Logger
- func NewSubsystemLogger(subsystem string, cfg Config, otelHandler slog.Handler) *slog.Logger
- func With(logger *slog.Logger, args ...any) *slog.Logger
- type Config
- type InstanceLogHandler
Constants ¶
const ( SubsystemAPI = "API" SubsystemCaddy = "CADDY" SubsystemImages = "IMAGES" SubsystemIngress = "INGRESS" SubsystemInstances = "INSTANCES" SubsystemNetwork = "NETWORK" SubsystemVolumes = "VOLUMES" SubsystemVMM = "VMM" SubsystemSystem = "SYSTEM" SubsystemExec = "EXEC" )
Subsystem names for per-subsystem logging configuration.
Variables ¶
This section is empty.
Functions ¶
func AddToContext ¶
AddToContext adds a logger to the context.
func FromContext ¶
FromContext retrieves the logger from context, or returns default.
func NewSubsystemLogger ¶
NewSubsystemLogger creates a logger for a specific subsystem with its configured level. If otelHandler is provided, logs will be sent both to stdout and to OTel.
Types ¶
type Config ¶
type Config struct {
// DefaultLevel is the default log level for all subsystems.
DefaultLevel slog.Level
// SubsystemLevels maps subsystem names to their specific log levels.
// If a subsystem is not in this map, DefaultLevel is used.
SubsystemLevels map[string]slog.Level
// AddSource adds source file information to log entries.
AddSource bool
}
Config holds logging configuration.
type InstanceLogHandler ¶
InstanceLogHandler wraps an slog.Handler and additionally writes logs that have an "id" attribute to a per-instance hypeman.log file. This provides automatic per-instance logging without manual instrumentation.
Implementation follows the slog handler guide for shared state across WithAttrs/WithGroup: https://pkg.go.dev/golang.org/x/example/slog-handler-guide
func NewInstanceLogHandler ¶
func NewInstanceLogHandler(wrapped slog.Handler, logPathFunc func(id string) string) *InstanceLogHandler
NewInstanceLogHandler creates a new handler that wraps the given handler and writes instance-related logs to per-instance log files. logPathFunc should return the path to hypeman.log for a given instance ID.
func (*InstanceLogHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level.
func (*InstanceLogHandler) Handle ¶
Handle processes a log record, passing it to the wrapped handler and optionally writing to a per-instance log file if "id" attribute is present.