-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathlogging.go
More file actions
39 lines (33 loc) · 1.23 KB
/
Copy pathlogging.go
File metadata and controls
39 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package meowcaller
import (
"github.com/purpshell/meowcaller/diag"
"github.com/rs/zerolog"
)
// Option configures optional, non-behavioral aspects of the call/media types —
// currently the diagnostic logger. The zero configuration logs nothing.
type Option func(*config)
type config struct {
log zerolog.Logger
diag *diag.Recorder
}
func resolveConfig(opts []Option) config {
c := config{log: zerolog.Nop()}
for _, opt := range opts {
opt(&c)
}
return c
}
// WithLogger sets the zerolog logger for debug/trace diagnostics. The library never
// configures logging itself; without this option the types are silent at zero cost.
// Pass the logger from a context, e.g. WithLogger(*zerolog.Ctx(ctx)).
func WithLogger(l zerolog.Logger) Option {
return func(c *config) { c.log = l }
}
// WithDiagnostics attaches a developer-only *diag.Recorder that dumps exact,
// per-category call diagnostics (including raw secrets and media) to JSONL files.
// This is an opt-in maintainer carve-out from the library's sanitized logging and
// must never be enabled in production. Without it the recorder is nil and every
// diag emit is a no-op at zero cost.
func WithDiagnostics(rec *diag.Recorder) Option {
return func(c *config) { c.diag = rec }
}