mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-04 22:00:20 +00:00
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (Windows) (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-1 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-2 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-3 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-4 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-5 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-6 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-7 (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-8 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-9 (push) Has been cancelled
Pipeline: Test, Lint, Build / Build-10 (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Signed-off-by: Deluan <deluan@navidrome.org>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package log
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// journalFormatter wraps a logrus.Formatter and prepends a syslog priority
|
|
// prefix (<N>) to each log line. When stderr is captured by systemd-journald,
|
|
// this prefix tells journald the correct severity for each message.
|
|
//
|
|
// See https://www.freedesktop.org/software/systemd/man/sd-daemon.html
|
|
type journalFormatter struct {
|
|
inner logrus.Formatter
|
|
}
|
|
|
|
// levelToPriority maps logrus levels to syslog priority values.
|
|
// The mapping follows RFC 5424 severity levels.
|
|
var levelToPriority = map[logrus.Level]int{
|
|
logrus.PanicLevel: 0, // emerg
|
|
logrus.FatalLevel: 2, // crit
|
|
logrus.ErrorLevel: 3, // err
|
|
logrus.WarnLevel: 4, // warning
|
|
logrus.InfoLevel: 6, // info
|
|
logrus.DebugLevel: 7, // debug
|
|
logrus.TraceLevel: 7, // debug
|
|
}
|
|
|
|
func (f *journalFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|
formatted, err := f.inner.Format(entry)
|
|
if err != nil {
|
|
return formatted, err
|
|
}
|
|
priority, ok := levelToPriority[entry.Level]
|
|
if !ok {
|
|
priority = 6 // default to info for unknown levels
|
|
}
|
|
prefix := fmt.Appendf(nil, "<%d>", priority)
|
|
return append(prefix, formatted...), nil
|
|
}
|