diff --git a/logging/journald.go b/logging/journald.go index 2573a2e..32b2113 100644 --- a/logging/journald.go +++ b/logging/journald.go @@ -19,6 +19,11 @@ import ( "github.com/rs/zerolog" ) +var replacements = map[string]string{ + "-": "_", + " ": "_", +} + const defaultJournalDPrio = journal.PriNotice func binaryFmt(p []byte) bool { @@ -66,6 +71,14 @@ func levelToJPrio(zLevel string) journal.Priority { return defaultJournalDPrio } +func replace(input string) (output string) { + output = input + for key, value := range replacements { + output = strings.ReplaceAll(output, key, value) + } + return +} + func (w journalWriter) Write(p []byte) (n int, err error) { var event map[string]interface{} origPLen := len(p) @@ -87,7 +100,7 @@ func (w journalWriter) Write(p []byte) (n int, err error) { msg := "" for key, value := range event { - jKey := strings.ToUpper(key) + jKey := replace(strings.ToUpper(key)) switch key { case zerolog.LevelFieldName, zerolog.TimestampFieldName: continue