/
level.go
35 lines (31 loc) · 986 Bytes
/
level.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package column
import (
"github.com/i582/cfmt/cmd/cfmt"
"github.com/pandich/couture/model"
"github.com/pandich/couture/model/level"
"github.com/pandich/couture/schema"
"github.com/pandich/couture/sink/color"
"github.com/pandich/couture/sink/layout"
)
type levelColumn struct {
extractorColumn
}
func newLevelColumn(styles map[level.Level]color.FgBgTuple, layout layout.ColumnLayout) column {
for _, lvl := range level.Levels {
formatLevel := string(schema.Level) + string(lvl)
cfmt.RegisterStyle(formatLevel, styles[lvl].Format())
}
return levelColumn{
extractorColumn: extractorColumn{
baseColumn: baseColumn{columnName: schema.Level, colLayout: layout},
extractor: func(event model.SinkEvent) []interface{} {
return []interface{}{string(event.Level)}
},
},
}
}
func (col levelColumn) render(event model.SinkEvent) string {
format := col.formatWithSuffix(string(event.Level))
value := col.extractor(event)
return cfmt.Sprintf(format, value...)
}