From 4789d2e869e254883d85b7ffe82f046d6eeef8bf Mon Sep 17 00:00:00 2001 From: Gusted <williamzijl7@hotmail.com> Date: Sun, 3 Jul 2022 02:12:19 +0200 Subject: [PATCH] Pass logger to fasthttp - Use a logger with `FASTHTTP` prefix as fasthttp's logger so it's easy to see what fasthttp is logging in console/journal. --- server/setup.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/setup.go b/server/setup.go index c186222..99a776c 100644 --- a/server/setup.go +++ b/server/setup.go @@ -5,12 +5,20 @@ import ( "net/http" "time" + "github.com/rs/zerolog/log" + "github.com/valyala/fasthttp" "codeberg.org/codeberg/pages/server/cache" "codeberg.org/codeberg/pages/server/utils" ) +type fasthttpLogger struct{} + +func (fasthttpLogger) Printf(format string, args ...interface{}) { + log.Printf("[FASTHTTP] "+format, args...) +} + func SetupServer(handler fasthttp.RequestHandler) *fasthttp.Server { // Enable compression by wrapping the handler with the compression function provided by FastHTTP compressedHandler := fasthttp.CompressHandlerBrotliLevel(handler, fasthttp.CompressBrotliBestSpeed, fasthttp.CompressBestSpeed) @@ -22,6 +30,7 @@ func SetupServer(handler fasthttp.RequestHandler) *fasthttp.Server { NoDefaultDate: true, ReadTimeout: 30 * time.Second, // needs to be this high for ACME certificates with ZeroSSL & HTTP-01 challenge Concurrency: 1024 * 32, // TODO: adjust bottlenecks for best performance with Gitea! + Logger: fasthttpLogger{}, } }