Utilities for slog for
calldepth
, add caller skip for helper functions e.g. in 3rd party libraries e.g. temporal et el.
calldepth: add caller skip, similar to that provided by
- zap provides
AddCallerSkip
—this plusWithOptions
allows for a simple adjustment in helpers as shown here - zerolog provides
Caller
andCallerSkipFrame
- go-kit/log provides
Caller
(and there's some discussion of makingCaller
even more helpful to users) - glog provides several
X-Depth
functions that allow the user to adjust the depth - the stdlib log provides
Output
code taken from golang/go#59145 (comment)
go get go.breu.io/slog-utils
Compatibility: go >= 1.21
⚠️ Work in Progress⚠️ Use this library carefully, log processing can be very costly (!)
package main
import (
"log/slog"
"go.temporal.io/sdk/client"
"go.breu.io/slog-utils/calldepth"
)
func main() {
adapter := calldepth.NewAdapter(
calldepth.NewLogger(slog.NewStdLogger()),
calldepth.WithCallDepth(5), // 5 for activities, 6 for workflows.
)
opts := client.Options{
HostPort: "localhost:7233",
Logger: adapter.WithGroup("temporal"),
}
tclient, err := client.Dial(opts)
}
Copyright © 2023 Breu Inc.
This project is MIT licensed.