mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-08-05 20:58:28 +02:00

Update logger to include browser UserAgent string in log lines. This will allow Crowdsec to filter for known bad useragents.
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package logger
|
|
|
|
/*
|
|
Traffic Log
|
|
|
|
This script log the traffic of HTTP requests
|
|
|
|
*/
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"imuslab.com/zoraxy/mod/netutils"
|
|
)
|
|
|
|
// Log HTTP request. Note that this must run in go routine to prevent any blocking
|
|
// in reverse proxy router
|
|
func (l *Logger) LogHTTPRequest(r *http.Request, reqclass string, statusCode int) {
|
|
go func() {
|
|
l.ValidateAndUpdateLogFilepath()
|
|
if l.logger == nil || l.file == nil {
|
|
//logger is not initiated. Do not log http request
|
|
return
|
|
}
|
|
clientIP := netutils.GetRequesterIP(r)
|
|
requestURI := r.RequestURI
|
|
statusCodeString := strconv.Itoa(statusCode)
|
|
//fmt.Println("[" + time.Now().Format("2006-01-02 15:04:05.000000") + "] [router:" + reqclass + "] [client " + clientIP + "] " + r.Method + " " + requestURI + " " + statusCodeString)
|
|
l.logger.Println("[" + time.Now().Format("2006-01-02 15:04:05.000000") + "] [router:" + reqclass + "] [origin:" + r.URL.Hostname() + "] [client: " + clientIP + "] [useragent: " + r.UserAgent() + "] " + r.Method + " " + requestURI + " " + statusCodeString)
|
|
}()
|
|
}
|