Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

log: fix deadlock when using systemd logging - fixes #8621

Nick Craig-Wood3cae37306455
diff --git a/fs/log/systemd_unix.go b/fs/log/systemd_unix.go
index a71bc6880..fa29b203c 100644
--- a/fs/log/systemd_unix.go
+++ b/fs/log/systemd_unix.go
@@ -5,10 +5,7 @@
package log
import (
- "fmt"
- "log"
"log/slog"
- "strconv"
"github.com/coreos/go-systemd/v22/journal"
"github.com/rclone/rclone/fs"
@@ -18,10 +15,8 @@ import (
func startSystemdLog(handler *OutputHandler) bool {
handler.clearFormatFlags(logFormatDate | logFormatTime | logFormatMicroseconds | logFormatUTC | logFormatLongFile | logFormatShortFile | logFormatPid)
handler.setFormatFlags(logFormatNoLevel)
- // TODO: Use the native journal.Print approach rather than a custom implementation
handler.SetOutput(func(level slog.Level, text string) {
- text = fmt.Sprintf("<%s>%-6s: %s", systemdLogPrefix(level), level, text)
- _ = log.Output(4, text)
+ _ = journal.Print(slogLevelToSystemdPriority(level), "%-6s: %s\n", level, text)
})
return true
}
@@ -37,12 +32,12 @@ var slogLevelToSystemdPrefix = map[slog.Level]journal.Priority{
slog.LevelDebug: journal.PriDebug,
}
-func systemdLogPrefix(l slog.Level) string {
+func slogLevelToSystemdPriority(l slog.Level) journal.Priority {
prio, ok := slogLevelToSystemdPrefix[l]
if !ok {
- return ""
+ return journal.PriInfo
}
- return strconv.Itoa(int(prio))
+ return prio
}
func isJournalStream() bool {