Files
job-search/internal/config/debug.go
T

46 lines
929 B
Go

package config
import (
"fmt"
"log/slog"
"os"
"reflect"
"slices"
"strings"
"github.com/spf13/viper"
)
// printEnv logs the JOBSEARCH* environment variables at debug level.
func printEnv() {
slog.Debug("Environment:")
env := os.Environ()
slices.Sort(env)
for _, e := range env {
pair := strings.SplitN(e, "=", 2)
if strings.HasPrefix(pair[0], EnvPrefix) {
slog.Debug("\t" + pair[0] + "=" + pair[1])
}
}
}
// printLoadedConfig logs every key Viper has loaded, with its value and type,
// at debug level.
func printLoadedConfig() {
slog.Debug("Loaded config:")
keys := viper.AllKeys()
for i := range keys {
k := keys[i]
v := viper.Get(k)
t := reflect.TypeOf(v)
slog.Debug(
"\t" + k + " = " + fmt.Sprintf("%#v", v) + " <" + t.Kind().String() + ">")
}
}
// printConfig logs conf at debug level.
func printConfig(conf JobSearchConfig) {
slog.Debug("Config:")
conf.PrintLog(slog.LevelDebug)
}