Merge branch 'appcolor'
This commit is contained in:
commit
eff3998eb7
1 changed files with 10 additions and 1 deletions
|
@ -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\"}}",
|
||||
|
|
Loading…
Reference in a new issue