ConsoleHandler used to find the file and line it prints by walking a fixed number of stack frames up from Handle. That count only fit a record logged through a slog.Logger and delivered through MultiplexHandler. It now reads them from the record's PC, the call site log/slog stores in every record it builds, the way the stdlib text handler does. A record whose PC is zero prints ???:0, as before. callerSkipFrames is gone.
New tests in console_handler_internal_test.go check the printed location against the line of the log call in three cases: a MultiplexHandler holding a ConsoleHandler, a ConsoleHandler used with slog.New, and a record built with runtime.Callers and passed to Handle. A fourth checks the ???:0 placeholder. Each test writes its log call inside a one-line function passed to lineOf, which returns the line it was called from; moving the log call to another line breaks the test.
The README's "When delivery fails" section no longer warns about the wrong location; it says the location comes from the record's PC, set with runtime.Callers.
Judgement call: the default-handler test builds a MultiplexHandler holding a ConsoleHandler instead of using slog.Default(), because the installed default holds a JSONHandler whenever stdout is not a terminal, which is the case under test.
Judgement call: the README gains one sentence on setting PC, so a reader following its advice does not get ???:0.
Model: opus-5-5
Fixes https://git.eeqj.de/sneak/simplelog/issues/36.
`ConsoleHandler` used to find the file and line it prints by walking a fixed number of stack frames up from `Handle`. That count only fit a record logged through a `slog.Logger` and delivered through `MultiplexHandler`. It now reads them from the record's `PC`, the call site `log/slog` stores in every record it builds, the way the stdlib text handler does. A record whose `PC` is zero prints `???:0`, as before. `callerSkipFrames` is gone.
New tests in `console_handler_internal_test.go` check the printed location against the line of the log call in three cases: a `MultiplexHandler` holding a `ConsoleHandler`, a `ConsoleHandler` used with `slog.New`, and a record built with `runtime.Callers` and passed to `Handle`. A fourth checks the `???:0` placeholder. Each test writes its log call inside a one-line function passed to `lineOf`, which returns the line it was called from; moving the log call to another line breaks the test.
The README's "When delivery fails" section no longer warns about the wrong location; it says the location comes from the record's `PC`, set with `runtime.Callers`.
Judgement call: the default-handler test builds a `MultiplexHandler` holding a `ConsoleHandler` instead of using `slog.Default()`, because the installed default holds a `JSONHandler` whenever stdout is not a terminal, which is the case under test.
Judgement call: the README gains one sentence on setting `PC`, so a reader following its advice does not get `???:0`.
Model: opus-5-5
ConsoleHandler found the file and line it prints by walking a fixed
number of stack frames up from itself, which only fit a record logged
through a slog.Logger and delivered through MultiplexHandler. It now
reads them from the record's PC, the call site slog stores, so a
ConsoleHandler used with slog.New and a record passed to Handle
directly print the right location too. A record whose PC is zero
prints ???:0 as before. The README drops its warning about the wrong
location and says how to set PC instead.
Model: opus-5-5
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.
Fixes #36.
ConsoleHandlerused to find the file and line it prints by walking a fixed number of stack frames up fromHandle. That count only fit a record logged through aslog.Loggerand delivered throughMultiplexHandler. It now reads them from the record'sPC, the call sitelog/slogstores in every record it builds, the way the stdlib text handler does. A record whosePCis zero prints???:0, as before.callerSkipFramesis gone.New tests in
console_handler_internal_test.gocheck the printed location against the line of the log call in three cases: aMultiplexHandlerholding aConsoleHandler, aConsoleHandlerused withslog.New, and a record built withruntime.Callersand passed toHandle. A fourth checks the???:0placeholder. Each test writes its log call inside a one-line function passed tolineOf, which returns the line it was called from; moving the log call to another line breaks the test.The README's "When delivery fails" section no longer warns about the wrong location; it says the location comes from the record's
PC, set withruntime.Callers.Judgement call: the default-handler test builds a
MultiplexHandlerholding aConsoleHandlerinstead of usingslog.Default(), because the installed default holds aJSONHandlerwhenever stdout is not a terminal, which is the case under test.Judgement call: the README gains one sentence on setting
PC, so a reader following its advice does not get???:0.Model: opus-5-5
Review passed.
Model: opus-5-5