MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / format

Method format

logger/formatter_structured.go:23–74  ·  view source on GitHub ↗

format formats a log record.

(r slog.Record)

Source from the content-addressed store, hash-verified

21
22// format formats a log record.
23func (s *formatterStructured) format(r slog.Record) {
24 s.prefix = newBuffer()
25 defer func() {
26 s.prefix.free()
27 }()
28
29 // Append timestamp
30 s.appendKey(slog.TimeKey)
31 s.appendTime(r.Time)
32
33 // Append log level
34 s.appendKey(slog.LevelKey)
35 s.appendString(s.levelName(r.Level), true)
36
37 // Append message
38 s.appendKey(slog.MessageKey)
39 s.appendString(r.Message, true)
40
41 // Append groups added with [Handler.WithAttrs] and [Handler.WithGroup]
42 for _, g := range s.groups {
43 if g.name != "" {
44 s.openGroup(g.name)
45 }
46
47 s.appendAttributes(g.attrs)
48 }
49
50 // Append attributes from the record
51 r.Attrs(func(attr slog.Attr) bool {
52 s.appendAttribute(attr)
53 return true
54 })
55
56 // Append error, source, and stack if present
57 if s.error.Key != "" {
58 s.appendKey(s.error.Key)
59 s.appendValue(s.error.Value)
60
61 if docsURL := s.errorDocsURL(); docsURL != nil {
62 s.appendKey(docsURL.Key)
63 s.appendValue(docsURL.Value)
64 }
65 }
66 if s.source.Key != "" {
67 s.appendKey(s.source.Key)
68 s.appendValue(s.source.Value)
69 }
70 if s.stack.Key != "" {
71 s.appendKey(s.stack.Key)
72 s.appendValue(s.stack.Value)
73 }
74}
75
76// appendAttributes appends a list of attributes to the buffer.
77func (s *formatterStructured) appendAttributes(attrs []slog.Attr) {

Callers

nothing calls this directly

Calls 11

appendKeyMethod · 0.95
openGroupMethod · 0.95
appendAttributesMethod · 0.95
appendAttributeMethod · 0.95
appendValueMethod · 0.95
freeMethod · 0.80
errorDocsURLMethod · 0.80
newBufferFunction · 0.70
appendTimeMethod · 0.45
appendStringMethod · 0.45
levelNameMethod · 0.45

Tested by

no test coverage detected