Logger should use slog.LevelVar for dynamic level switching #8

Closed
opened 2026-03-01 19:07:35 +01:00 by clawbot · 0 comments
Collaborator

Per GO_HTTP_SERVER_CONVENTIONS §9 (Logger Setup with TTY Detection), the logger should use slog.LevelVar to allow dynamic log level changes without recreating the handler:

l.level = new(slog.LevelVar)
l.level.Set(slog.LevelInfo)
// ...
opts := &slog.HandlerOptions{Level: l.level}

Currently, internal/logger/logger.go EnableDebugLogging() recreates the entire slog.Handler and slog.Logger just to change the level. This means any component that cached the *slog.Logger from Get() before EnableDebugLogging() was called will still use the old info-level logger.

Using slog.LevelVar allows changing the level atomically without replacing the handler, and all existing references to the logger automatically respect the new level.

Per GO_HTTP_SERVER_CONVENTIONS §9 (Logger Setup with TTY Detection), the logger should use `slog.LevelVar` to allow dynamic log level changes without recreating the handler: ```go l.level = new(slog.LevelVar) l.level.Set(slog.LevelInfo) // ... opts := &slog.HandlerOptions{Level: l.level} ``` Currently, `internal/logger/logger.go` `EnableDebugLogging()` recreates the entire `slog.Handler` and `slog.Logger` just to change the level. This means any component that cached the `*slog.Logger` from `Get()` before `EnableDebugLogging()` was called will still use the old info-level logger. Using `slog.LevelVar` allows changing the level atomically without replacing the handler, and all existing references to the logger automatically respect the new level.
clawbot added the
bot
label 2026-03-01 19:07:35 +01:00
sneak closed this issue 2026-03-04 01:19:43 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/webhooker#8
No description provided.