mirror of
https://github.com/matrix-org/dendrite
synced 2024-11-19 00:00:55 +01:00
mediaapi/writers/upload: Add standard fields to logger
So that they apply to all log messages thereafter
This commit is contained in:
parent
5922ad383d
commit
e33438a37e
1 changed files with 2 additions and 5 deletions
|
@ -86,7 +86,7 @@ func parseAndValidateRequest(req *http.Request, cfg *config.MediaAPI) (*uploadRe
|
||||||
ContentType: types.ContentType(req.Header.Get("Content-Type")),
|
ContentType: types.ContentType(req.Header.Get("Content-Type")),
|
||||||
UploadName: types.Filename(url.PathEscape(req.FormValue("filename"))),
|
UploadName: types.Filename(url.PathEscape(req.FormValue("filename"))),
|
||||||
},
|
},
|
||||||
Logger: util.GetLogger(req.Context()),
|
Logger: util.GetLogger(req.Context()).WithField("Origin", cfg.ServerName),
|
||||||
}
|
}
|
||||||
|
|
||||||
if resErr := r.Validate(cfg.MaxFileSizeBytes); resErr != nil {
|
if resErr := r.Validate(cfg.MaxFileSizeBytes); resErr != nil {
|
||||||
|
@ -98,10 +98,9 @@ func parseAndValidateRequest(req *http.Request, cfg *config.MediaAPI) (*uploadRe
|
||||||
|
|
||||||
func (r *uploadRequest) doUpload(reqReader io.Reader, cfg *config.MediaAPI, db *storage.Database) *util.JSONResponse {
|
func (r *uploadRequest) doUpload(reqReader io.Reader, cfg *config.MediaAPI, db *storage.Database) *util.JSONResponse {
|
||||||
r.Logger.WithFields(log.Fields{
|
r.Logger.WithFields(log.Fields{
|
||||||
"Origin": r.MediaMetadata.Origin,
|
|
||||||
"UploadName": r.MediaMetadata.UploadName,
|
"UploadName": r.MediaMetadata.UploadName,
|
||||||
"FileSizeBytes": r.MediaMetadata.FileSizeBytes,
|
"FileSizeBytes": r.MediaMetadata.FileSizeBytes,
|
||||||
"Content-Type": r.MediaMetadata.ContentType,
|
"ContentType": r.MediaMetadata.ContentType,
|
||||||
}).Info("Uploading file")
|
}).Info("Uploading file")
|
||||||
|
|
||||||
// The file data is hashed and the hash is used as the MediaID. The hash is useful as a
|
// The file data is hashed and the hash is used as the MediaID. The hash is useful as a
|
||||||
|
@ -111,8 +110,6 @@ func (r *uploadRequest) doUpload(reqReader io.Reader, cfg *config.MediaAPI, db *
|
||||||
hash, bytesWritten, tmpDir, err := fileutils.WriteTempFile(reqReader, cfg.MaxFileSizeBytes, cfg.AbsBasePath)
|
hash, bytesWritten, tmpDir, err := fileutils.WriteTempFile(reqReader, cfg.MaxFileSizeBytes, cfg.AbsBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Logger.WithError(err).WithFields(log.Fields{
|
r.Logger.WithError(err).WithFields(log.Fields{
|
||||||
"Origin": r.MediaMetadata.Origin,
|
|
||||||
"MediaID": r.MediaMetadata.MediaID,
|
|
||||||
"MaxFileSizeBytes": cfg.MaxFileSizeBytes,
|
"MaxFileSizeBytes": cfg.MaxFileSizeBytes,
|
||||||
}).Warn("Error while transferring file")
|
}).Warn("Error while transferring file")
|
||||||
fileutils.RemoveDir(tmpDir, r.Logger)
|
fileutils.RemoveDir(tmpDir, r.Logger)
|
||||||
|
|
Loading…
Reference in a new issue