2024-06-28 15:28:54 +02:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
2024-07-03 10:00:21 +02:00
|
|
|
"strconv"
|
2024-06-30 08:55:07 +02:00
|
|
|
|
2024-07-03 10:00:21 +02:00
|
|
|
"code.lila.network/adoralaura/certwarden-deploy/internal/configuration"
|
2024-06-28 15:28:54 +02:00
|
|
|
)
|
|
|
|
|
2024-07-03 10:00:21 +02:00
|
|
|
func InitializeLogger() *slog.Logger {
|
2024-06-30 08:55:07 +02:00
|
|
|
logLevel := slog.LevelInfo
|
|
|
|
|
2024-07-03 10:00:21 +02:00
|
|
|
if configuration.VerboseLogging {
|
2024-06-30 08:55:07 +02:00
|
|
|
logLevel = slog.LevelDebug
|
|
|
|
}
|
2024-07-03 10:00:21 +02:00
|
|
|
if configuration.QuietLogging {
|
2024-06-30 08:55:07 +02:00
|
|
|
logLevel = slog.LevelError
|
|
|
|
}
|
2024-07-03 10:00:21 +02:00
|
|
|
if configuration.DryRun {
|
|
|
|
logLevel = slog.LevelDebug
|
|
|
|
}
|
2024-06-28 15:28:54 +02:00
|
|
|
|
|
|
|
opts := &slog.HandlerOptions{
|
2024-07-11 16:10:34 +02:00
|
|
|
Level: logLevel,
|
2024-06-28 15:28:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handler := slog.NewTextHandler(os.Stdout, opts)
|
2024-07-03 10:00:21 +02:00
|
|
|
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))
|
2024-06-28 15:28:54 +02:00
|
|
|
|
2024-07-03 10:00:21 +02:00
|
|
|
return log
|
2024-06-28 15:28:54 +02:00
|
|
|
}
|