diff options
| author | Gibheer <gibheer+git@zero-knowledge.org> | 2023-09-05 15:23:43 +0200 | 
|---|---|---|
| committer | Gibheer <gibheer+git@zero-knowledge.org> | 2023-09-05 15:23:43 +0200 | 
| commit | 71cd89a4f1b5d99a48dd02d4e87d1e461b5c94dc (patch) | |
| tree | c67c257a34727d9766074486696c60dc58b547ca | |
| parent | 26a4ca6ab56d23054f606bc378ba355cebce485a (diff) | |
add debug log support for the checker
This makes it possible to use this library and get a debug checker
output.
| -rw-r--r-- | monzero.go | 13 | 
1 files changed, 13 insertions, 0 deletions
@@ -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 {  | 
