mediaapi/writers/download: Always log origin and mediaID

main
Robert Swain 2017-05-31 14:30:57 +02:00
parent a45f008c12
commit 9606ea28ce
1 changed files with 7 additions and 15 deletions

View File

@ -53,7 +53,10 @@ func Download(w http.ResponseWriter, req *http.Request, origin gomatrixserverlib
MediaID: mediaID, MediaID: mediaID,
Origin: origin, Origin: origin,
}, },
Logger: util.GetLogger(req.Context()), Logger: util.GetLogger(req.Context()).WithFields(log.Fields{
"Origin": origin,
"MediaID": mediaID,
}),
} }
// request validation // request validation
@ -181,8 +184,6 @@ func (r *downloadRequest) respondFromLocalFile(w http.ResponseWriter, absBasePat
} }
r.Logger.WithFields(log.Fields{ r.Logger.WithFields(log.Fields{
"MediaID": r.MediaMetadata.MediaID,
"Origin": r.MediaMetadata.Origin,
"UploadName": r.MediaMetadata.UploadName, "UploadName": r.MediaMetadata.UploadName,
"Base64Hash": r.MediaMetadata.Base64Hash, "Base64Hash": r.MediaMetadata.Base64Hash,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
@ -214,24 +215,15 @@ func (r *downloadRequest) respondFromLocalFile(w http.ResponseWriter, absBasePat
} }
func (r *downloadRequest) closeConnection(w http.ResponseWriter) { func (r *downloadRequest) closeConnection(w http.ResponseWriter) {
r.Logger.WithFields(log.Fields{ r.Logger.Info("Attempting to close the connection.")
"Origin": r.MediaMetadata.Origin,
"MediaID": r.MediaMetadata.MediaID,
}).Info("Attempting to close the connection.")
hijacker, ok := w.(http.Hijacker) hijacker, ok := w.(http.Hijacker)
if ok { if ok {
connection, _, hijackErr := hijacker.Hijack() connection, _, hijackErr := hijacker.Hijack()
if hijackErr == nil { if hijackErr == nil {
r.Logger.WithFields(log.Fields{ r.Logger.Info("Closing")
"Origin": r.MediaMetadata.Origin,
"MediaID": r.MediaMetadata.MediaID,
}).Info("Closing")
connection.Close() connection.Close()
} else { } else {
r.Logger.WithError(hijackErr).WithFields(log.Fields{ r.Logger.WithError(hijackErr).Warn("Error trying to hijack and close connection")
"Origin": r.MediaMetadata.Origin,
"MediaID": r.MediaMetadata.MediaID,
}).Warn("Error trying to hijack and close connection")
} }
} }
} }