Replace log with slog

This commit is contained in:
Ian Fijolek
2021-05-10 20:12:18 -07:00
parent f0e179851f
commit fda9e1bfc3
8 changed files with 56 additions and 61 deletions
+12 -10
View File
@@ -3,8 +3,8 @@ package main
import (
"errors"
"io/ioutil"
"log"
"git.iamthefij.com/iamthefij/slog"
"gopkg.in/yaml.v2"
)
@@ -53,32 +53,36 @@ func (config Config) IsValid() (isValid bool) {
// Validate alerts
if config.Alerts == nil || len(config.Alerts) == 0 {
// This should never happen because there is a default alert named 'log' for now
log.Printf("ERROR: Invalid alert configuration: Must provide at least one alert")
slog.Errorf("Invalid alert configuration: Must provide at least one alert")
isValid = false
}
for _, alert := range config.Alerts {
if !alert.IsValid() {
log.Printf("ERROR: Invalid alert configuration: %s", alert.Name)
slog.Errorf("Invalid alert configuration: %s", alert.Name)
isValid = false
}
}
// Validate monitors
if config.Monitors == nil || len(config.Monitors) == 0 {
log.Printf("ERROR: Invalid monitor configuration: Must provide at least one monitor")
slog.Errorf("Invalid monitor configuration: Must provide at least one monitor")
isValid = false
}
for _, monitor := range config.Monitors {
if !monitor.IsValid() {
log.Printf("ERROR: Invalid monitor configuration: %s", monitor.Name)
slog.Errorf("Invalid monitor configuration: %s", monitor.Name)
isValid = false
}
// Check that all Monitor alerts actually exist
for _, isUp := range []bool{true, false} {
for _, alertName := range monitor.GetAlertNames(isUp) {
if _, ok := config.Alerts[alertName]; !ok {
log.Printf(
"ERROR: Invalid monitor configuration: %s. Unknown alert %s",
slog.Errorf(
"Invalid monitor configuration: %s. Unknown alert %s",
monitor.Name, alertName,
)
isValid = false
@@ -114,9 +118,7 @@ func LoadConfig(filePath string) (config Config, err error) {
return
}
if LogDebug {
log.Printf("DEBUG: Config values:\n%v\n", config)
}
slog.Debugf("Config values:\n%v\n", config)
// Add log alert if not present
if PyCompat {