MCPcopy Create free account
hub / github.com/bufbuild/buf / Handle

Method Handle

private/pkg/slogapp/console.go:131–155  ·  view source on GitHub ↗

Handle implements the slog.Handler interface.

(ctx context.Context, r slog.Record)

Source from the content-addressed store, hash-verified

129
130// Handle implements the slog.Handler interface.
131func (c *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
132 c.lock.Lock()
133 defer c.lock.Unlock()
134 c.buffer.Reset()
135 if c.enableColor {
136 c.buffer.WriteString(colorize(r.Level.String(), getColor(r.Level)))
137 } else {
138 c.buffer.WriteString(r.Level.String())
139 }
140 c.buffer.WriteString(consoleSeparator)
141 c.buffer.WriteString(r.Message)
142 bufN := c.buffer.Len()
143 c.buffer.WriteString(consoleSeparator)
144 // Delegate must always be called, as it may have attributes to write.
145 if err := c.delegate.Handle(ctx, r); err != nil {
146 return err
147 }
148 if c.buffer.Len() == bufN+len(consoleSeparator+"{}\n") {
149 // No attributes to write, trim the buffer to remove the empty JSON object.
150 c.buffer.Truncate(bufN)
151 c.buffer.WriteByte('\n')
152 }
153 _, err := c.buffer.WriteTo(c.out)
154 return err
155}
156
157// WithAttrs implements the slog.Handler interface.
158func (c *consoleHandler) WithAttrs(attrs []slog.Attr) slog.Handler {

Callers 1

newTestReflectionServerFunction · 0.45

Calls 7

colorizeFunction · 0.85
getColorFunction · 0.85
LenMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
StringMethod · 0.65
ResetMethod · 0.45

Tested by 1

newTestReflectionServerFunction · 0.36