|
@@ -7,6 +7,7 @@ import (
|
|
"text/template"
|
|
"text/template"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
+ "github.com/mgutz/ansi"
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
"gopkg.in/mgo.v2/bson"
|
|
"gopkg.in/mgo.v2/bson"
|
|
)
|
|
)
|
|
@@ -26,18 +27,30 @@ func init() {
|
|
return dt.Format(time.RFC822)
|
|
return dt.Format(time.RFC822)
|
|
},
|
|
},
|
|
"sevName": func(s int) string {
|
|
"sevName": func(s int) string {
|
|
- names := []string{"emerg", "alert", "crit", "err", "warn", "notice", "info", "dbg"}
|
|
|
|
- if s >= len(names) {
|
|
|
|
|
|
+ names := []string{"emerg ", "alert ", "crit ", "err ", "warn ", "notice", "info ", "dbg "}
|
|
|
|
+ switch {
|
|
|
|
+ case s < 2: // emerg..alert
|
|
|
|
+ return ansi.Color(names[s], "red+b")
|
|
|
|
+ case s < 4: // emerg..err
|
|
|
|
+ return ansi.Color(names[s], "red")
|
|
|
|
+ case s < 6: // warn..notice
|
|
|
|
+ return ansi.Color(names[s], "white+b")
|
|
|
|
+ case s >= len(names):
|
|
return "???"
|
|
return "???"
|
|
|
|
+ default:
|
|
|
|
+ return names[s]
|
|
}
|
|
}
|
|
- return names[s]
|
|
|
|
},
|
|
},
|
|
|
|
+ "color": func(color, text string) string {
|
|
|
|
+ return ansi.Color(text, color) // slow; should use colorfunc
|
|
|
|
+ },
|
|
|
|
+ "red": ansi.ColorFunc("red+b"),
|
|
}
|
|
}
|
|
syslogTmpl = template.Must(template.New("syslog").Funcs(tmplFuncs).Parse(
|
|
syslogTmpl = template.Must(template.New("syslog").Funcs(tmplFuncs).Parse(
|
|
- "{{rfc822 (index . \"timestamp\")}} {{index . \"hostname\"}} " +
|
|
|
|
|
|
+ "{{color \"yellow\" (rfc822 (index . \"timestamp\")) }} {{index . \"hostname\"}} " +
|
|
"{{index . \"app_name\"}}" +
|
|
"{{index . \"app_name\"}}" +
|
|
"{{ if (ne (index . \"proc_id\") \"-\")}}[{{index . \"proc_id\"}}]{{end}}: " +
|
|
"{{ if (ne (index . \"proc_id\") \"-\")}}[{{index . \"proc_id\"}}]{{end}}: " +
|
|
- "<{{ sevName (index . \"severity\") }}> " +
|
|
|
|
|
|
+ "{{ sevName (index . \"severity\") }} " +
|
|
"{{index . \"message\"}}",
|
|
"{{index . \"message\"}}",
|
|
))
|
|
))
|
|
}
|
|
}
|