https://github.com/kaihendry/slogd
Structured LOGging Duration
https://github.com/kaihendry/slogd
go golang slog tracing
Last synced: 3 months ago
JSON representation
Structured LOGging Duration
- Host: GitHub
- URL: https://github.com/kaihendry/slogd
- Owner: kaihendry
- License: mit
- Created: 2023-02-02T06:55:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-10T13:17:31.000Z (over 3 years ago)
- Last Synced: 2025-04-18T16:55:24.603Z (about 1 year ago)
- Topics: go, golang, slog, tracing
- Language: Go
- Homepage: https://pkg.go.dev/github.com/kaihendry/slogd
- Size: 6.84 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slog duration
No need for heavyweight tracing tools like X-ray, Jaeger or Zipkin. "slogd"
measures the time for a function to return an error object.
Inspired by @[tj](https://github.com/tj)'s [Apex logs's Trace function](https://pkg.go.dev/github.com/apex/log#Trace)
- https://github.com/apex/log/blob/master/_examples/trace/trace.go
- https://github.com/apex/log/blob/8da83152b5d6177b4bfe3d12810a5afd25355170/entry.go#L142-L158
## [slogd example](https://github.com/kaihendry/slogfest)
Sample code:
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout)))
url := "https://httpbin.org/delay/2"
var err error
// Caveat: Only one defer slogd per function!
defer slogd.New("fetching", "url", url).Stop(&err)
_, err = http.Get(url)
Sample output:
time=2023-02-10T20:21:46.564+08:00 level=INFO msg=fetching url=https://httpbin.org/delay/2 duration=3.716787544s