Skip to content

Commit

Permalink
chore: additional initLogger cleanup
Browse files Browse the repository at this point in the history
No need to create another log instance, simply change the
log level once config is loaded.
  • Loading branch information
retr0h committed Jan 20, 2024
1 parent 220c4c0 commit e6f2d6d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,12 @@ func init() {
_ = viper.BindPFlag("giltFile", rootCmd.PersistentFlags().Lookup("gilt-file"))
_ = viper.BindPFlag("giltDir", rootCmd.PersistentFlags().Lookup("gilt-dir"))
_ = viper.BindPFlag("repositories", rootCmd.PersistentFlags().Lookup("repositories"))
}

func getLogger(logLevel slog.Leveler) *slog.Logger {
return slog.New(
tint.NewHandler(os.Stderr, &tint.Options{
Level: logLevel,
TimeFormat: time.Kitchen,
NoColor: !term.IsTerminal(int(os.Stdout.Fd())),
}),
)
cobra.OnInitialize(initLogger)
}

func logFatal(message string, logGroup any) {
log := getLogger(slog.LevelError)
log.Error(
logger.Error(
message,
logGroup,
)
Expand All @@ -106,7 +97,13 @@ func initLogger() {
logLevel = slog.LevelDebug
}

logger = getLogger(logLevel)
logger = slog.New(
tint.NewHandler(os.Stderr, &tint.Options{
Level: logLevel,
TimeFormat: time.Kitchen,
NoColor: !term.IsTerminal(int(os.Stdout.Fd())),
}),
)
}

func initConfig() {
Expand Down

0 comments on commit e6f2d6d

Please sign in to comment.