enable different log levels
This commit is contained in:
parent
a08df81967
commit
9b5bda5042
3 changed files with 27 additions and 2 deletions
|
@ -8,6 +8,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"code.lila.network/adoralaura/certwarden-deploy/internal/cli"
|
"code.lila.network/adoralaura/certwarden-deploy/internal/cli"
|
||||||
|
"code.lila.network/adoralaura/certwarden-deploy/internal/config"
|
||||||
|
"code.lila.network/adoralaura/certwarden-deploy/internal/logger"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cfgFile string
|
var cfgFile string
|
||||||
|
@ -20,3 +23,13 @@ func Execute() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cobra.OnInitialize(config.InitializeConfig, logger.InitializeLogger)
|
||||||
|
|
||||||
|
cli.RootCmd.PersistentFlags().BoolVarP(&config.VerboseLogging, "verbose", "v", false, "Enable verbose logging")
|
||||||
|
cli.RootCmd.PersistentFlags().BoolVarP(&config.DryRun, "dry-run", "d", false, "Just show the would-be changes without changing the file system")
|
||||||
|
cli.RootCmd.PersistentFlags().BoolVarP(&config.QuietLogging, "quiet", "q", false, "Disable any logging (if both -q and -v are set, quiet wins)")
|
||||||
|
cli.RootCmd.PersistentFlags().StringVarP(&config.ConfigFile, "config", "c", "/etc/certwarden-deploy/config.yaml", "Path to config file (default is /etc/certwarden-deploy/config.yaml)")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ import "log/slog"
|
||||||
var Config *ConfigFileData
|
var Config *ConfigFileData
|
||||||
var ConfigFile *string
|
var ConfigFile *string
|
||||||
var Logger *slog.Logger
|
var Logger *slog.Logger
|
||||||
|
var DryRun bool
|
||||||
|
var QuietLogging bool
|
||||||
|
var VerboseLogging bool
|
||||||
|
|
||||||
type ConfigFileData struct {
|
type ConfigFileData struct {
|
||||||
BaseURL string `yaml:"base_url"`
|
BaseURL string `yaml:"base_url"`
|
||||||
|
|
|
@ -3,13 +3,22 @@ package logger
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"code.lila.network/adoralaura/certwarden-deploy/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitializeLogger() {
|
func InitializeLogger() {
|
||||||
// TODO: Different Log levels
|
logLevel := slog.LevelInfo
|
||||||
|
|
||||||
|
if config.VerboseLogging {
|
||||||
|
logLevel = slog.LevelDebug
|
||||||
|
}
|
||||||
|
if config.QuietLogging {
|
||||||
|
logLevel = slog.LevelError
|
||||||
|
}
|
||||||
|
|
||||||
opts := &slog.HandlerOptions{
|
opts := &slog.HandlerOptions{
|
||||||
Level: slog.LevelInfo,
|
Level: logLevel,
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := slog.NewTextHandler(os.Stdout, opts)
|
handler := slog.NewTextHandler(os.Stdout, opts)
|
||||||
|
|
Loading…
Reference in a new issue