(_ context.Context, r slog.Record)
| 30 | } |
| 31 | |
| 32 | func (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 | |
| 68 | func (h *debugLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler { |
| 69 | newAttrs := make([]slog.Attr, len(h.attrs)+len(attrs)) |
nothing calls this directly
no test coverage detected