54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"maps"
|
|
"slices"
|
|
)
|
|
|
|
// 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, sorted by key, 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...))
|
|
}
|
|
}
|
|
|
|
flat := conf.Flatten()
|
|
for _, k := range slices.Sorted(maps.Keys(flat)) {
|
|
logFn("\t", k, " = ", flat[k])
|
|
}
|
|
}
|