feat(server): add syslog priority prefixes for systemd-journald (#5192)
* fix: add syslog priority prefixes for systemd-journald When running under systemd, all log messages were assigned priority 3 (error) by journald because navidrome wrote plain text to stderr without syslog priority prefixes. Add a journalFormatter that wraps the existing logrus formatter and prepends <N> syslog priority prefixes (RFC 5424) to each log line. The formatter is automatically enabled when the JOURNAL_STREAM environment variable is set (indicating the process is managed by systemd). Priority mapping: - Fatal/Panic → <2>/<0> (crit/emerg) - Error → <3> (err) - Warn → <4> (warning) - Info → <6> (info) - Debug/Trace → <7> (debug) Fixes #5142 * test: refactor journalFormatter tests to use Ginkgo and DescribeTable Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ = Describe("journalFormatter", func() {
|
||||
var formatter *journalFormatter
|
||||
|
||||
BeforeEach(func() {
|
||||
inner := &logrus.TextFormatter{
|
||||
DisableTimestamp: true,
|
||||
DisableColors: true,
|
||||
}
|
||||
formatter = &journalFormatter{inner: inner}
|
||||
})
|
||||
|
||||
DescribeTable("prefixes log lines with syslog priority",
|
||||
func(level logrus.Level, expectedPrefix string) {
|
||||
entry := &logrus.Entry{
|
||||
Logger: logrus.New(),
|
||||
Level: level,
|
||||
Message: "test message",
|
||||
Data: logrus.Fields{},
|
||||
}
|
||||
out, err := formatter.Format(entry)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(string(out)).To(HavePrefix(expectedPrefix))
|
||||
},
|
||||
Entry("error", logrus.ErrorLevel, "<3>"),
|
||||
Entry("warning", logrus.WarnLevel, "<4>"),
|
||||
Entry("info", logrus.InfoLevel, "<6>"),
|
||||
Entry("debug", logrus.DebugLevel, "<7>"),
|
||||
Entry("trace", logrus.TraceLevel, "<7>"),
|
||||
Entry("fatal", logrus.FatalLevel, "<2>"),
|
||||
Entry("panic", logrus.PanicLevel, "<0>"),
|
||||
Entry("unknown level defaults to info", logrus.Level(99), "<6>"),
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user