Skip to content

Commit 66a035b

Browse files
committed
attach LogRequestHandler when logger is enabled
1 parent 39a7d42 commit 66a035b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/app/app.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/andybalholm/brotli"
88
lru "github.com/hashicorp/golang-lru"
99
"go-http-server/param"
10+
"go-http-server/util"
1011
"golang.org/x/exp/slices"
1112
"io"
1213
"mime"
@@ -256,9 +257,16 @@ func (app *App) HandlerFuncNew(w http.ResponseWriter, r *http.Request) {
256257
}
257258

258259
func (app *App) Listen() {
260+
var handlerFunc http.Handler = http.HandlerFunc(app.HandlerFuncNew)
261+
if app.params.Logger {
262+
handlerFunc = util.LogRequestHandler(handlerFunc, &util.LogRequestHandlerOptions{
263+
Pretty: app.params.LogPretty,
264+
})
265+
}
266+
259267
app.server = &http.Server{
260268
Addr: fmt.Sprintf("%s:%d", app.params.Address, app.params.Port),
261-
Handler: http.HandlerFunc(app.HandlerFuncNew),
269+
Handler: handlerFunc,
262270
}
263271

264272
fmt.Printf("Server listening on http://%s\n", app.server.Addr)

0 commit comments

Comments
 (0)