aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 {