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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
ConsoleHandler.Handlefinds 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 aslog.Loggermethod and delivered throughMultiplexHandler. On any other path the location is wrong: aConsoleHandlerused on its own withslog.New, a handler wrapped by another handler, or a record passed toHandledirectly. The last of these is what the README section "When delivery fails" in #35 tells callers to do; called frommain, it prints a file inside the Go runtime.log/slogalready stores the call site inslog.Record.PC, andJSONHandleralready 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
ConsoleHandlertakes the file and line fromrecord.PC(runtime.CallersFrames). A record with noPC(zero) prints the same placeholder as today (???and line 0).callerSkipFramesis gone.ConsoleHandlerused directly withslog.New, and for a record built with aPCand passed toHandledirectly.Handledirectly gets the wrong file and line.Implementation requirements
logpackage;TestJSONHandlerDeadlockstays.(closes #<this issue>).Model: opus-5-5