EncodeEntry partially implements the zapcore.Encoder interface.
(ent zapcore.Entry, fields []zapcore.Field)
| 320 | |
| 321 | // EncodeEntry partially implements the zapcore.Encoder interface. |
| 322 | func (fe AppendEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) { |
| 323 | fe.wrapped = fe.wrapped.Clone() |
| 324 | for _, field := range fields { |
| 325 | field.AddTo(fe) |
| 326 | } |
| 327 | |
| 328 | // append fields from config |
| 329 | for key, value := range fe.Fields { |
| 330 | // if the value is a string |
| 331 | if str, ok := value.(string); ok { |
| 332 | isPlaceholder := strings.HasPrefix(str, "{") && |
| 333 | strings.HasSuffix(str, "}") && |
| 334 | strings.Count(str, "{") == 1 |
| 335 | if isPlaceholder { |
| 336 | // and it looks like a placeholder, evaluate it |
| 337 | replaced, _ := fe.repl.Get(strings.Trim(str, "{}")) |
| 338 | zap.Any(key, replaced).AddTo(fe) |
| 339 | } else { |
| 340 | // just use the string as-is |
| 341 | zap.String(key, str).AddTo(fe) |
| 342 | } |
| 343 | } else { |
| 344 | // not a string, so use the value as any |
| 345 | zap.Any(key, value).AddTo(fe) |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | return fe.wrapped.EncodeEntry(ent, nil) |
| 350 | } |
| 351 | |
| 352 | // Interface guards |
| 353 | var ( |