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)
| 186 | // substituted with a colour-decorated string when colour output is available, |
| 187 | // or with the plain field value otherwise. |
| 188 | func (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. |
| 207 | func (f *ColorFormatter) colourTag(tag string, e *Event) string { |