Skip to content

Comments

httplog: add structured logger#1030

Merged
Choraden merged 8 commits intomainfrom
hg/http_slog
Mar 27, 2025
Merged

httplog: add structured logger#1030
Choraden merged 8 commits intomainfrom
hg/http_slog

Conversation

@Choraden
Copy link
Contributor

Structured http logs will be needed once we migrate to log/slog.

This improves package structure.
This follows similar pattern as normal logger and log writer, except here we have structuredLogBuilder.
Copy link
Contributor

@markamsauce markamsauce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

More elegant. Does a deep copy.
Although, we assume request won't be nil, it's better to validate that.
go test -bench=. -benchmem -benchtime 10s
goos: darwin
goarch: arm64
pkg: github.com/saucelabs/forwarder/httplog
cpu: Apple M1 Pro
BenchmarkNormalShortURL-10              33868418               352.9 ns/op           288 B/op         11 allocs/op
BenchmarkNormalHeaders-10                3090453              3852 ns/op            7480 B/op         52 allocs/op
BenchmarkNormalBody-10                   2540685              4772 ns/op           10299 B/op         60 allocs/op
BenchmarkStructuredShortURL-10          42058107               287.0 ns/op           464 B/op          8 allocs/op
BenchmarkStructuredHeaders-10            7712139              1558 ns/op            2704 B/op         22 allocs/op
BenchmarkStructuredBody-10               6497708              1852 ns/op            3904 B/op         30 allocs/op
PASS

Note: Actual performance may vary depending on the logFunc implementation and the sink.
@Choraden
Copy link
Contributor Author

I decided to apply some improvements. PTAL @markamsauce.

Copy link
Contributor

@markamsauce markamsauce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK for me.

@Choraden Choraden merged commit ea55aa8 into main Mar 27, 2025
6 checks passed
@Choraden Choraden deleted the hg/http_slog branch March 27, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants