From 52c94ffa7bae5f0ebe2148b8b25bcaf298e52ddf Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Thu, 16 Dec 2021 17:40:25 +0200 Subject: [PATCH] [server] Wrap fasthttp and Go http logging into custom logger. --- sources/cmd/server/server.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sources/cmd/server/server.go b/sources/cmd/server/server.go index 4fc239e..d47d9f1 100644 --- a/sources/cmd/server/server.go +++ b/sources/cmd/server/server.go @@ -10,6 +10,7 @@ import "crypto/tls" import "flag" import "fmt" import "io" +import "io/ioutil" import "log" import "net" import "net/http" @@ -500,6 +501,15 @@ func (_server *server) ServeHTTP (_response http.ResponseWriter, _request *http. +func (_server *server) Printf (_format string, _arguments ... interface{}) () { + if !_server.quiet { + log.Printf ("[ee] [47765179] [fasthttp] " + _format, _arguments ...) + } +} + + + + func Main () () { log.SetPrefix (fmt.Sprintf ("[%8d] ", os.Getpid ())) @@ -834,12 +844,12 @@ func main_0 () (error) { if _limitMemory != 0 { _processArguments = append (_processArguments, "--limit-memory", fmt.Sprintf ("%d", _limitMemory)) } - if _debug { - _processArguments = append (_processArguments, "--debug") - } if _quiet { _processArguments = append (_processArguments, "--quiet") } + if _debug { + _processArguments = append (_processArguments, "--debug") + } if _dummy { _processArguments = append (_processArguments, "--dummy") } @@ -1230,8 +1240,8 @@ func main_0 () (error) { securityHeadersEnabled : _securityHeadersEnabled, http1Disabled : _http1Disabled, http2Disabled : _http2Disabled, - debug : _debug, quiet : _quiet, + debug : _debug, dummy : _dummy, delay : _delay, } @@ -1322,6 +1332,8 @@ func main_0 () (error) { CloseOnShutdown : true, DisableKeepalive : false, + Logger : _server, + } @@ -1356,6 +1368,11 @@ func main_0 () (error) { panic ("[1b618ffe]") } + if !_quiet { + _https2Server.ErrorLog = log.New (os.Stderr, log.Prefix () + "[ee] [f734edc4] [gohttp] ", 0) + } else { + _https2Server.ErrorLog = log.New (ioutil.Discard, "", 0) + }