8000 log: fix deadlock when using systemd logging - fixes #8621 · rclone/rclone@3cae373 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cae373

Browse files
committed
log: fix deadlock when using systemd logging - fixes #8621
In this commit the logging system was re-worked dfa4d94 fs: Remove github.com/sirupsen/logrus and replace with log/slog Unfortunately the systemd logging was still using the plain log package and this caused a deadlock as it was recursively calling the logging package. The fix was to use the dedicated systemd journal logging routines in the process removing a TODO!
1 parent b6b8526 commit 3cae373

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

fs/log/systemd_unix.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
package log
66

77
import (
8-
"fmt"
9-
"log"
108
"log/slog"
11-
"strconv"
129

1310
"github.com/coreos/go-systemd/v22/journal"
1411
"github.com/rclone/rclone/fs"
@@ -18,10 +15,8 @@ import (
1815
func startSystemdLog(handler *OutputHandler) bool {
1916
handler.clearFormatFlags(logFormatDate | logFormatTime | logFormatMicroseconds | logFormatUTC | logFormatLongFile | logFormatShortFile | logFormatPid)
2017
handler.setFormatFlags(logFormatNoLevel)
21-
// TODO: Use the native journal.Print approach rather than a custom implementation
2218
handler.SetOutput(func(level slog.Level, text string) {
23-
text = fmt.Sprintf("<%s>%-6s: %s", systemdLogPrefix(level), level, text)
24-
_ = log.Output(4, text)
19+
_ = journal.Print(slogLevelToSystemdPriority(level), "%-6s: %s\n", level, text)
2520
})
2621
return true
2722
}
@@ -37,12 +32,12 @@ var slogLevelToSystemdPrefix = map[slog.Level]journal.Priority{
3732
slog.LevelDebug: journal.PriDebug,
3833
}
3934

40-
func systemdLogPrefix(l slog.Level) string {
35+
func slogLevelToSystemdPriority(l slog.Level) journal.Priority {
4136
prio, ok := slogLevelToSystemdPrefix[l]
4237
if !ok {
43-
return ""
38+
return journal.PriInfo
4439
}
45-
return strconv.Itoa(int(prio))
40+
return prio
4641
}
4742

4843
func isJournalStream() bool {

0 commit comments

Comments
 (0)
0