ConsoleHandler prints the wrong file and line unless the record came through slog.Logger and MultiplexHandler #36

Closed
opened 2026-10-06 04:52:58 +02:00 by clawbot · 0 comments
Collaborator

ConsoleHandler.Handle finds the file and line it prints by going a fixed number of stack frames (callerSkipFrames = 4) up from itself. That count only fits a record logged through a slog.Logger method and delivered through MultiplexHandler. On any other path the location is wrong: a ConsoleHandler used on its own with slog.New, a handler wrapped by another handler, or a record passed to Handle directly. The last of these is what the README section "When delivery fails" in #35 tells callers to do; called from main, it prints a file inside the Go runtime. log/slog already stores the call site in slog.Record.PC, and JSONHandler already emits it.

Found in the review of #35. Starts after that PR lands, since it removes the README warning that PR adds.

Definition of done

  • ConsoleHandler takes the file and line from record.PC (runtime.CallersFrames). A record with no PC (zero) prints the same placeholder as today (??? and line 0).
  • callerSkipFrames is gone.
  • Tests show the printed file and line are the call site for a record logged through the default handler, for a ConsoleHandler used directly with slog.New, and for a record built with a PC and passed to Handle directly.
  • The README no longer warns that a record passed to Handle directly gets the wrong file and line.
  • The full check is green.

Implementation requirements

  • No path back into the stdlib log package; TestJSONHandlerDeadlock stays.
  • Landing commit title must end with (closes #<this issue>).

Model: opus-5-5

`ConsoleHandler.Handle` finds the file and line it prints by going a fixed number of stack frames (`callerSkipFrames = 4`) up from itself. That count only fits a record logged through a `slog.Logger` method and delivered through `MultiplexHandler`. On any other path the location is wrong: a `ConsoleHandler` used on its own with `slog.New`, a handler wrapped by another handler, or a record passed to `Handle` directly. The last of these is what the README section "When delivery fails" in https://git.eeqj.de/sneak/simplelog/pulls/35 tells callers to do; called from `main`, it prints a file inside the Go runtime. `log/slog` already stores the call site in `slog.Record.PC`, and `JSONHandler` already emits it. Found in the review of https://git.eeqj.de/sneak/simplelog/pulls/35. Starts after that PR lands, since it removes the README warning that PR adds. ## Definition of done - `ConsoleHandler` takes the file and line from `record.PC` (`runtime.CallersFrames`). A record with no `PC` (zero) prints the same placeholder as today (`???` and line 0). - `callerSkipFrames` is gone. - Tests show the printed file and line are the call site for a record logged through the default handler, for a `ConsoleHandler` used directly with `slog.New`, and for a record built with a `PC` and passed to `Handle` directly. - The README no longer warns that a record passed to `Handle` directly gets the wrong file and line. - The full check is green. ## Implementation requirements - No path back into the stdlib `log` package; `TestJSONHandlerDeadlock` stays. - Landing commit title must end with ` (closes #<this issue>)`. Model: opus-5-5
clawbot self-assigned this 2026-10-06 04:52:58 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/simplelog#36