Rework logging

This commit is contained in:
Matt Joiner 2022-12-07 10:43:33 +11:00
parent c23269d1cc
commit 68dc90a7f7
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
1 changed files with 3 additions and 3 deletions

View File

@ -34,8 +34,6 @@ func unmarshalQueryKeyToArray(w http.ResponseWriter, key string, query url.Value
return
}
var Logger = log.NewLogger("anacrolix", "torrent", "tracker", "http", "server")
// Returns false if there was an error and it was served.
func (me Handler) requestHostAddr(r *http.Request) (_ netip.Addr, err error) {
if me.RequestHost != nil {
@ -48,6 +46,8 @@ func (me Handler) requestHostAddr(r *http.Request) (_ netip.Addr, err error) {
return netip.ParseAddr(host)
}
var requestHeadersLogger = log.Default.WithNames("request", "headers")
func (me Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vs := r.URL.Query()
var event tracker.AnnounceEvent
@ -64,7 +64,7 @@ func (me Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
Logger.WithNames("request").Levelf(log.Debug, "request RemoteAddr=%q, header=%q", r.RemoteAddr, r.Header)
requestHeadersLogger.Levelf(log.Debug, "request RemoteAddr=%q, header=%q", r.RemoteAddr, r.Header)
addr, err := me.requestHostAddr(r)
if err != nil {
log.Printf("error getting requester IP: %v", err)