-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbifrost.go
38 lines (30 loc) · 1015 Bytes
/
bifrost.go
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
// Package bifrost contains an API client for the Bifrost CA service.
package bifrost
import (
"context"
"log/slog"
"sync/atomic"
)
var (
// LogLevel is the log level used by the bifrost logger.
LogLevel = new(slog.LevelVar)
logger atomic.Pointer[slog.Logger]
)
// Logger returns the global Bifrost logger.
func Logger() *slog.Logger {
return logger.Load()
}
// SetLogger sets the [*slog.Logger] used by bifrost.
// The default handler disables logging.
func SetLogger(l *slog.Logger) {
logger.Store(l)
}
func init() {
SetLogger(slog.New(discardHandler{}))
}
// discardHandler is an [slog.Handler] which is always disabled and therefore logs nothing.
type discardHandler struct{}
func (discardHandler) Enabled(context.Context, slog.Level) bool { return false }
func (discardHandler) Handle(context.Context, slog.Record) error { return nil }
func (d discardHandler) WithAttrs([]slog.Attr) slog.Handler { return d }
func (d discardHandler) WithGroup(string) slog.Handler { return d }