Merge branch 'appcolor'

This commit is contained in:
boyska 2019-01-03 16:00:00 +01:00
commit eff3998eb7

View file

@ -3,6 +3,7 @@ package formatter
import (
"encoding/json"
"fmt"
"hash/fnv"
"io"
"text/template"
"time"
@ -45,10 +46,18 @@ func init() {
return ansi.Color(text, color) // slow; should use colorfunc
},
"red": ansi.ColorFunc("red+b"),
"autoColor": func(s string) string {
// from https://weechat.org/blog/post/2011/08/28/Beautify-your-WeeChat
palette := []string{"31", "35", "38", "40", "49", "63", "70", "80", "92", "99", "112", "126", "130", "138", "142", "148", "167", "169", "174", "176", "178", "184", "186", "210", "212", "215", "247"}
hash := fnv.New32()
hash.Write([]byte(s))
picked := palette[int(hash.Sum32())%len(palette)]
return ansi.Color(s, picked)
},
}
syslogTmpl = template.Must(template.New("syslog").Funcs(tmplFuncs).Parse(
"{{color \"yellow\" (rfc822 (index . \"timestamp\")) }} {{index . \"hostname\"}} " +
"{{index . \"app_name\"}}" +
"{{index . \"app_name\" | autoColor}}" +
"{{ if (ne (index . \"proc_id\") \"-\")}}[{{index . \"proc_id\"}}]{{end}}: " +
"{{ sevName (index . \"severity\") }} " +
"{{index . \"message\"}}",