Browse Source

tail: log severity name

boyska 5 years ago
parent
commit
6d1ddba736
1 changed files with 8 additions and 0 deletions
  1. 8 0
      formatter/format.go

+ 8 - 0
formatter/format.go

@@ -25,11 +25,19 @@ func init() {
 		"rfc822": func(dt time.Time) string {
 			return dt.Format(time.RFC822)
 		},
+		"sevName": func(s int) string {
+			names := []string{"emerg", "alert", "crit", "err", "warn", "notice", "info", "dbg"}
+			if s >= len(names) {
+				return "???"
+			}
+			return names[s]
+		},
 	}
 	syslogTmpl = template.Must(template.New("syslog").Funcs(tmplFuncs).Parse(
 		"{{rfc822 (index . \"timestamp\")}} {{index . \"hostname\"}} " +
 			"{{index . \"app_name\"}}" +
 			"{{ if (ne (index . \"proc_id\") \"-\")}}[{{index . \"proc_id\"}}]{{end}}: " +
+			"<{{ sevName (index . \"severity\") }}> " +
 			"{{index . \"message\"}}",
 	))
 }