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

51 lines
1.1 KiB
Go

package config
import (
"fmt"
"log/slog"
)
// PrintTerminal prints the configuration to stdout as String formats it.
func (conf JobSearchConfig) PrintTerminal() {
fmt.Print(conf.String() + "\n")
}
// PrintJson prints the configuration to stdout as JSON.
func (conf JobSearchConfig) PrintJson() {
fmt.Print(conf.JSON() + "\n")
}
// PrintYaml prints the configuration to stdout as YAML.
func (conf JobSearchConfig) PrintYaml() {
fmt.Print(conf.YAML() + "\n")
}
// PrintLog logs each configuration key and value at atLevel: debug, warn,
// error, or info for any other level.
func (conf JobSearchConfig) PrintLog(atLevel slog.Level) {
var logFn func(args ...interface{})
switch atLevel {
case slog.LevelDebug:
logFn = func(args ...interface{}) {
slog.Debug(fmt.Sprint(args...))
}
case slog.LevelError:
logFn = func(args ...interface{}) {
slog.Error(fmt.Sprint(args...))
}
case slog.LevelWarn:
logFn = func(args ...interface{}) {
slog.Warn(fmt.Sprint(args...))
}
default:
logFn = func(args ...interface{}) {
slog.Info(fmt.Sprint(args...))
}
}
for k, v := range conf.Flatten() {
logFn("\t", k, " = ", v)
}
}