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

50 lines
1.0 KiB
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 set by the config file or an environment
// variable (see isExplicitlySet), with its value and type, at debug level.
func printLoadedConfig() {
slog.Debug("Loaded config:")
keys := viper.AllKeys()
for i := range keys {
k := keys[i]
if isExplicitlySet(k) {
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)
}