certwarden-deploy/internal/logger/logger.go

39 lines
889 B
Go

package logger
import (
"log/slog"
"os"
"strconv"
"code.lila.network/adoralaura/certwarden-deploy/internal/configuration"
)
func InitializeLogger() *slog.Logger {
logLevel := slog.LevelInfo
sourceLogging := false
if configuration.VerboseLogging {
logLevel = slog.LevelDebug
sourceLogging = true
}
if configuration.QuietLogging {
logLevel = slog.LevelError
}
if configuration.DryRun {
logLevel = slog.LevelDebug
}
opts := &slog.HandlerOptions{
Level: logLevel,
AddSource: sourceLogging,
}
handler := slog.NewTextHandler(os.Stdout, opts)
log := slog.New(handler)
log.Debug("configuration.VerboseLogging is " + strconv.FormatBool(configuration.VerboseLogging))
log.Debug("configuration.QuietLogging is " + strconv.FormatBool(configuration.QuietLogging))
log.Debug("configuration.DryRun is " + strconv.FormatBool(configuration.DryRun))
return log
}