-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a global logger for all library and application logs. Users can set this log to customise log output.
- Loading branch information
Showing
14 changed files
with
113 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.