transfer logs: add error field

Fixes #1638

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-05-27 19:35:48 +02:00
parent 6c94173ca1
commit 9c775e2213
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
2 changed files with 9 additions and 4 deletions

View file

@ -352,6 +352,9 @@ func (t *BaseTransfer) checkUploadOutsideHomeDir(err error) int {
if err == nil { if err == nil {
return 0 return 0
} }
if t.ErrTransfer == nil {
t.ErrTransfer = err
}
if Config.TempPath == "" { if Config.TempPath == "" {
return 0 return 0
} }
@ -410,7 +413,8 @@ func (t *BaseTransfer) Close() error {
var uploadFileSize int64 var uploadFileSize int64
if t.transferType == TransferDownload { if t.transferType == TransferDownload {
logger.TransferLog(downloadLogSender, t.fsPath, elapsed, t.BytesSent.Load(), t.Connection.User.Username, logger.TransferLog(downloadLogSender, t.fsPath, elapsed, t.BytesSent.Load(), t.Connection.User.Username,
t.Connection.ID, t.Connection.protocol, t.Connection.localAddr, t.Connection.remoteAddr, t.ftpMode) t.Connection.ID, t.Connection.protocol, t.Connection.localAddr, t.Connection.remoteAddr, t.ftpMode,
t.ErrTransfer)
ExecuteActionNotification(t.Connection, operationDownload, t.fsPath, t.requestPath, "", "", "", //nolint:errcheck ExecuteActionNotification(t.Connection, operationDownload, t.fsPath, t.requestPath, "", "", "", //nolint:errcheck
t.BytesSent.Load(), t.ErrTransfer, elapsed, t.metadata) t.BytesSent.Load(), t.ErrTransfer, elapsed, t.metadata)
} else { } else {
@ -431,7 +435,8 @@ func (t *BaseTransfer) Close() error {
t.updateQuota(numFiles, uploadFileSize) t.updateQuota(numFiles, uploadFileSize)
t.updateTimes() t.updateTimes()
logger.TransferLog(uploadLogSender, t.fsPath, elapsed, t.BytesReceived.Load(), t.Connection.User.Username, logger.TransferLog(uploadLogSender, t.fsPath, elapsed, t.BytesReceived.Load(), t.Connection.User.Username,
t.Connection.ID, t.Connection.protocol, t.Connection.localAddr, t.Connection.remoteAddr, t.ftpMode) t.Connection.ID, t.Connection.protocol, t.Connection.localAddr, t.Connection.remoteAddr, t.ftpMode,
t.ErrTransfer)
} }
if t.ErrTransfer != nil { if t.ErrTransfer != nil {
t.Connection.Log(logger.LevelError, "transfer error: %v, path: %q", t.ErrTransfer, t.fsPath) t.Connection.Log(logger.LevelError, "transfer error: %v, path: %q", t.ErrTransfer, t.fsPath)

View file

@ -203,7 +203,7 @@ func ErrorToConsole(format string, v ...any) {
// TransferLog logs uploads or downloads // TransferLog logs uploads or downloads
func TransferLog(operation, path string, elapsed int64, size int64, user, connectionID, protocol, localAddr, func TransferLog(operation, path string, elapsed int64, size int64, user, connectionID, protocol, localAddr,
remoteAddr, ftpMode string, remoteAddr, ftpMode string, err error,
) { ) {
ev := logger.Info(). ev := logger.Info().
Timestamp(). Timestamp().
@ -219,7 +219,7 @@ func TransferLog(operation, path string, elapsed int64, size int64, user, connec
if ftpMode != "" { if ftpMode != "" {
ev.Str("ftp_mode", ftpMode) ev.Str("ftp_mode", ftpMode)
} }
ev.Send() ev.AnErr("error", err).Send()
} }
// CommandLog logs an SFTP/SCP/SSH command // CommandLog logs an SFTP/SCP/SSH command