Open
Description
When using a slog-strict logger with a slog.Handler
that sets AddSource
in slog.HandlerOptions
the added source block displays the slog-strict wrapping function as the source as opposed to the caller.
Example:
package main
import (
"context"
"log/slog"
"os"
slogstrict "github.com/go-swiss/slog-strict"
)
func main() {
logger := slogstrict.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))
logger.Info(context.Background(), "test")
}
Outputs:
{
"time": "2023-11-22T13:03:55.879954-05:00",
"level": "INFO",
"source": {
"function": "github.com/go-swiss/slog-strict.logger.Info",
"file": "/Users/travbale/go/pkg/mod/github.com/go-swiss/slog-strict@v0.0.0-20231026122839-ccffde83385b/slogstrict.go",
"line": 56
},
"msg": "test"
}
The function
indicated as the source of the call is slog-strict.logger.Info
rather than main
.
The slog
documentation calls out how wrappers should properly handle this logic.
Metadata
Metadata
Assignees
Labels
No labels