fix(lib): add the ability to set a custom slog Logger (#915)
* fix(lib): add the ability to set a custom slog Logger Closes #864 * test(lib): amend s.check usage Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net> Signed-off-by: Xe Iaso <xe.iaso@techaro.lol>
This commit is contained in:
parent
6ae386a11a
commit
1f7fcf938b
6 changed files with 25 additions and 17 deletions
|
|
@ -43,6 +43,7 @@ type Options struct {
|
|||
OpenGraph config.OpenGraph
|
||||
ServeRobotsTXT bool
|
||||
CookieSecure bool
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
func LoadPoliciesOrDefault(ctx context.Context, fname string, defaultDifficulty int) (*policy.ParsedConfig, error) {
|
||||
|
|
@ -89,8 +90,12 @@ func LoadPoliciesOrDefault(ctx context.Context, fname string, defaultDifficulty
|
|||
}
|
||||
|
||||
func New(opts Options) (*Server, error) {
|
||||
if opts.Logger == nil {
|
||||
opts.Logger = slog.With("subsystem", "anubis")
|
||||
}
|
||||
|
||||
if opts.ED25519PrivateKey == nil && opts.HS512Secret == nil {
|
||||
slog.Debug("opts.PrivateKey not set, generating a new one")
|
||||
opts.Logger.Debug("opts.PrivateKey not set, generating a new one")
|
||||
_, priv, err := ed25519.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("lib: can't generate private key: %v", err)
|
||||
|
|
@ -108,6 +113,7 @@ func New(opts Options) (*Server, error) {
|
|||
opts: opts,
|
||||
OGTags: ogtags.NewOGTagCache(opts.Target, opts.Policy.OpenGraph, opts.Policy.Store),
|
||||
store: opts.Policy.Store,
|
||||
logger: opts.Logger,
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue