From 6d1ddba736c84e3f17a2d877cee6144e8e692676 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 2 Jan 2019 13:57:34 +0100 Subject: [PATCH] tail: log severity name --- formatter/format.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/formatter/format.go b/formatter/format.go index 94a4176..aa8912c 100644 --- a/formatter/format.go +++ b/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\"}}", )) }