| 1 | package scribe |
| 2 | |
| 3 | import ( |
| 4 | "log/slog" |
| 5 | ) |
| 6 | |
| 7 | // NewJSONHandler creates a JSON handler with the scribe options API. |
| 8 | // This is a convenience wrapper around slog.JSONHandler for consistency. |
| 9 | func NewJSONHandler(opts ...Option) slog.Handler { |
| 10 | o := defaultOptions() |
| 11 | for _, opt := range opts { |
| 12 | if opt != nil { |
| 13 | opt(o) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | return slog.NewJSONHandler(o.writer, &slog.HandlerOptions{ |
| 18 | Level: o.level, |
| 19 | AddSource: o.addSource, |
| 20 | ReplaceAttr: o.replaceAttr, |
| 21 | }) |
| 22 | } |
| 23 | |
| 24 | // NewTextHandler creates a text handler with the scribe options API. |
| 25 | // This is a convenience wrapper around slog.TextHandler for consistency. |
| 26 | func NewTextHandler(opts ...Option) slog.Handler { |
| 27 | o := defaultOptions() |
| 28 | for _, opt := range opts { |
| 29 | if opt != nil { |
| 30 | opt(o) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return slog.NewTextHandler(o.writer, &slog.HandlerOptions{ |
| 35 | Level: o.level, |
| 36 | AddSource: o.addSource, |
| 37 | ReplaceAttr: o.replaceAttr, |
| 38 | }) |
| 39 | } |
| 40 | |