aboutsummaryrefslogtreecommitdiff
path: root/monzero.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2023-09-05 15:23:43 +0200
committerGibheer <gibheer+git@zero-knowledge.org>2023-09-05 15:23:43 +0200
commit71cd89a4f1b5d99a48dd02d4e87d1e461b5c94dc (patch)
treec67c257a34727d9766074486696c60dc58b547ca /monzero.go
parent26a4ca6ab56d23054f606bc378ba355cebce485a (diff)
add debug log support for the checker
This makes it possible to use this library and get a debug checker output.
Diffstat (limited to 'monzero.go')
-rw-r--r--monzero.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/monzero.go b/monzero.go
index f2481a5..0e9fa76 100644
--- a/monzero.go
+++ b/monzero.go
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
+ "log/slog"
"time"
)
@@ -19,6 +20,7 @@ type (
executor func(Check, context.Context) CheckResult
timeout time.Duration
ident string // the host identifier
+ logger *slog.Logger
}
CheckerConfig struct {
@@ -42,6 +44,9 @@ type (
// HostIdentifier is used in notifications to point to the source of the
// notification.
HostIdentifier string
+
+ // Checker will send debug details to the logger for each command executed.
+ Logger *slog.Logger
}
// Check is contains the metadata to run a check and its current state.
@@ -75,6 +80,7 @@ func NewChecker(cfg CheckerConfig) (*Checker, error) {
executor: cfg.Executor,
timeout: cfg.Timeout,
ident: cfg.HostIdentifier,
+ logger: cfg.Logger,
}
if c.executor == nil {
return nil, fmt.Errorf("executor must not be nil")
@@ -116,6 +122,13 @@ func (c *Checker) Next() error {
result.Message = fmt.Sprintf("check took longer than %s", c.timeout)
result.ExitCode = 2
}
+ c.logger.Debug(
+ "check command run",
+ "id", check.id,
+ "command", check.Command,
+ "exit code", result.ExitCode,
+ "message", result.Message,
+ )
backToOkay := false
if len(check.ExitCodes) == 0 && result.ExitCode == 0 {