MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / Format

Method Format

pkg/event/formatter.go:188–204  ·  view source on GitHub ↗

Format renders the event according to the template. Each {{ .Field }} tag is substituted with a colour-decorated string when colour output is available, or with the plain field value otherwise.

(e *Event)

Source from the content-addressed store, hash-verified

186// substituted with a colour-decorated string when colour output is available,
187// or with the plain field value otherwise.
188func (f *ColorFormatter) Format(e *Event) []byte {
189 if !f.enabled {
190 return f.f.Format(e)
191 }
192
193 var b bytes.Buffer
194 b.WriteString(e.Type.arrow())
195
196 // fasttemplate.Template.ExecuteFuncString calls tagWriter once per tag in
197 // document order, passing the bare tag name (e.g. ".Seq", ".Type",
198 // ".Params.file_path"). The writer writes the coloured substitution value.
199 _, _ = f.f.t.ExecuteFunc(&b, func(w io.Writer, tag string) (int, error) {
200 return io.WriteString(w, f.colourTag(tag, e))
201 })
202
203 return bytes.TrimRight(b.Bytes(), "\n")
204}
205
206// colourTag maps a bare tag name to its coloured string representation.
207func (f *ColorFormatter) colourTag(tag string, e *Event) string {

Callers 5

PublishMethod · 0.45
replaceMethod · 0.45
GetMethod · 0.45
FireMethod · 0.45
TestMarshallerFunction · 0.45

Calls 3

colourTagMethod · 0.95
arrowMethod · 0.80
ExecuteFuncMethod · 0.80

Tested by 1

TestMarshallerFunction · 0.36