From 6732d654a47b439c0c68f7403ada528ff7f74a8b Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Tue, 13 Jun 2023 16:05:40 +0200 Subject: [PATCH] =?UTF-8?q?Reduce=20the=20amount=20of=20useless=20data=20i?= =?UTF-8?q?n=20request=E2=80=99s=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I tried to have a log line that uses the “common” format from Apache, because i thought that it would help me reuse regexps i have defined for fail2ban filters and such. However, it makes no much sense. For once, i was repeating the date and time: log.Printf already does that for me. And, second, i do not need that data in Numerus’ log because i always run it behind a proxy that _has_ a “common”-formatted log file, so there is no need for me to repeat all that data again. What i need is the IP, to know whether remotedAdd() function works as expected; the method, to check that the override does its job; the path, to know what resource the browser requested; the response status code, so that i do not need to open the browser console for that; the response size, to keep on eye that i do not return a lot of data; and the total response time, to realize how long my unoptimized SQL queries slows the application down. The rest, Apache should do its job and record it in its log file for fail2ban and whatever i need the logs for in the future. --- pkg/logger.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pkg/logger.go b/pkg/logger.go index 5720384..881c900 100644 --- a/pkg/logger.go +++ b/pkg/logger.go @@ -41,20 +41,12 @@ func Logger(handler http.Handler) http.Handler { if statusCode == 0 { statusCode = http.StatusOK } - referer := r.Referer() - if referer == "" { - referer = "-" - } - stdout.Printf("HTTP - %s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %s\n", + stdout.Printf("HTTP - %s %s \"%s\" %d %d %s\n", remoteAddr(r), - t.Format("02/Jan/2006:15:04:05 -0700"), r.Method, r.URL.Path, - r.Proto, statusCode, logger.responseSize, - referer, - r.UserAgent(), time.Since(t), )