MCPcopy Index your code
hub / github.com/micro/go-micro / Handle

Method Handle

logger/debug_handler.go:32–66  ·  view source on GitHub ↗
(_ context.Context, r slog.Record)

Source from the content-addressed store, hash-verified

30}
31
32func (h *debugLogHandler) Handle(_ context.Context, r slog.Record) error {
33 // Build metadata from attributes
34 metadata := make(map[string]string)
35
36 // Add handler's attributes
37 for _, attr := range h.attrs {
38 metadata[attr.Key] = attr.Value.String()
39 }
40
41 // Add record's attributes
42 r.Attrs(func(a slog.Attr) bool {
43 metadata[a.Key] = a.Value.String()
44 return true
45 })
46
47 // Add level to metadata
48 metadata["level"] = r.Level.String()
49
50 // Add source if available
51 if sourcePath := extractSourceFilePath(r.PC); sourcePath != "" {
52 metadata["file"] = sourcePath
53 }
54
55 // Create debug log record
56 rec := dlog.Record{
57 Timestamp: r.Time,
58 Message: r.Message,
59 Metadata: metadata,
60 }
61
62 // Write to debug log
63 _ = dlog.DefaultLog.Write(rec)
64
65 return nil
66}
67
68func (h *debugLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
69 newAttrs := make([]slog.Attr, len(h.attrs)+len(attrs))

Callers

nothing calls this directly

Calls 3

extractSourceFilePathFunction · 0.85
StringMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected