gin
gin copied to clipboard
Optimize the logger middleware
Use the out.Write to write the log content immediately, because the LogFormatter returns a string, the fmt.Fprint is unnecessary here.
The benchmark test result:
Command:
go test -test.v -test.bench ^BenchmarkLoggerMiddleware$
Environment:
version: go1.18.3
goos: windows
goarch: amd64
pkg: github.com/gin-gonic/gin
cpu: Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
Result:
BenchmarkLoggerMiddleware(New Pull Request)
BenchmarkLoggerMiddleware-16 1244007 951.5 ns/op 270 B/op 14 allocs/op
BenchmarkLoggerMiddleware(Old Master)
BenchmarkLoggerMiddleware-16 1000000 1036 ns/op 288 B/op 16 allocs/op
Codecov Report
Merging #3016 (8dbee16) into master (92dd245) will increase coverage by
0.00%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #3016 +/- ##
=======================================
Coverage 98.06% 98.06%
=======================================
Files 43 43
Lines 3148 3150 +2
=======================================
+ Hits 3087 3089 +2
Misses 48 48
Partials 13 13
| Flag | Coverage Δ | |
|---|---|---|
| go-1.15 | 98.06% <100.00%> (+<0.01%) |
:arrow_up: |
| go-1.16 | 98.03% <100.00%> (+<0.01%) |
:arrow_up: |
| go-1.17 | 97.96% <100.00%> (+<0.01%) |
:arrow_up: |
| go-1.18 | 97.96% <100.00%> (+<0.01%) |
:arrow_up: |
| macos-latest | 98.06% <100.00%> (+<0.01%) |
:arrow_up: |
| nomsgpack | 98.03% <100.00%> (+<0.01%) |
:arrow_up: |
| ubuntu-latest | 98.06% <100.00%> (+<0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| logger.go | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 92dd245...8dbee16. Read the comment docs.