MCPcopy
hub / github.com/tuna/tunasync / Handle

Method Handle

internal/logger.go:142–180  ·  view source on GitHub ↗
(_ context.Context, record slog.Record)

Source from the content-addressed store, hash-verified

140}
141
142func (h *lineHandler) Handle(_ context.Context, record slog.Record) error {
143 var b strings.Builder
144
145 if h.withSystemd {
146 b.WriteString("[")
147 b.WriteString(levelLabel(record.Level))
148 b.WriteString("] ")
149 } else {
150 b.WriteString("[")
151 b.WriteString(record.Time.Format("06-01-02 15:04:05"))
152 b.WriteString("][")
153 b.WriteString(levelLabel(record.Level))
154 b.WriteString("]")
155 if h.addSource {
156 if src := shortSource(record.PC); src != "" {
157 b.WriteString("[")
158 b.WriteString(src)
159 b.WriteString("]")
160 }
161 }
162 b.WriteString(" ")
163 }
164
165 b.WriteString(record.Message)
166
167 attrs := append([]slog.Attr{}, h.attrs...)
168 record.Attrs(func(attr slog.Attr) bool {
169 attrs = append(attrs, attr)
170 return true
171 })
172 appendAttrs(&b, h.groups, attrs)
173
174 b.WriteByte('\n')
175
176 h.mu.Lock()
177 defer h.mu.Unlock()
178 _, err := io.WriteString(h.w, b.String())
179 return err
180}
181
182func (h *lineHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
183 cloned := *h

Callers 3

logMethod · 0.80

Calls 4

levelLabelFunction · 0.85
shortSourceFunction · 0.85
appendAttrsFunction · 0.85
StringMethod · 0.45

Tested by 2