writePart appends a formatted part to buf.
(buf *bytes.Buffer, evt map[string]interface{}, p string)
| 288 | |
| 289 | // writePart appends a formatted part to buf. |
| 290 | func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, p string) { |
| 291 | var f Formatter |
| 292 | var fvn FormatterByFieldName |
| 293 | |
| 294 | if len(w.PartsExclude) > 0 { |
| 295 | for _, exclude := range w.PartsExclude { |
| 296 | if exclude == p { |
| 297 | return |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | switch p { |
| 303 | case LevelFieldName: |
| 304 | if w.FormatLevel == nil { |
| 305 | f = consoleDefaultFormatLevel(w.NoColor) |
| 306 | } else { |
| 307 | f = w.FormatLevel |
| 308 | } |
| 309 | case TimestampFieldName: |
| 310 | if w.FormatTimestamp == nil { |
| 311 | f = consoleDefaultFormatTimestamp(w.TimeFormat, w.TimeLocation, w.NoColor) |
| 312 | } else { |
| 313 | f = w.FormatTimestamp |
| 314 | } |
| 315 | case MessageFieldName: |
| 316 | if w.FormatMessage == nil { |
| 317 | f = consoleDefaultFormatMessage(w.NoColor, evt[LevelFieldName]) |
| 318 | } else { |
| 319 | f = w.FormatMessage |
| 320 | } |
| 321 | case CallerFieldName: |
| 322 | if w.FormatCaller == nil { |
| 323 | f = consoleDefaultFormatCaller(w.NoColor) |
| 324 | } else { |
| 325 | f = w.FormatCaller |
| 326 | } |
| 327 | default: |
| 328 | if w.FormatPartValueByName != nil { |
| 329 | fvn = w.FormatPartValueByName |
| 330 | } else if w.FormatFieldValue != nil { |
| 331 | f = w.FormatFieldValue |
| 332 | } else { |
| 333 | f = consoleDefaultFormatFieldValue |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | var s string |
| 338 | if f == nil { |
| 339 | s = fvn(evt[p], p) |
| 340 | } else { |
| 341 | s = f(evt[p]) |
| 342 | } |
| 343 | |
| 344 | if len(s) > 0 { |
| 345 | if buf.Len() > 0 { |
| 346 | buf.WriteByte(' ') // Write space only if not the first part |
| 347 | } |
no test coverage detected