MCPcopy Create free account
hub / github.com/caddyserver/caddy / EncodeEntry

Method EncodeEntry

modules/logging/appendencoder.go:322–350  ·  view source on GitHub ↗

EncodeEntry partially implements the zapcore.Encoder interface.

(ent zapcore.Entry, fields []zapcore.Field)

Source from the content-addressed store, hash-verified

320
321// EncodeEntry partially implements the zapcore.Encoder interface.
322func (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
353var (

Callers

nothing calls this directly

Calls 3

GetMethod · 0.65
CloneMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected