Reduce the amount of useless data in request’s log
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.
This commit is contained in:
parent
eb207a01fc
commit
6732d654a4
|
@ -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),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue