Skip to content

Commit

Permalink
fix(config): Fix log level and format not respecting envs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed May 1, 2024
1 parent e39857d commit 48abba8
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions internal/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"io"
"os"

"github.com/clevyr/kubedb/internal/consts"
"github.com/fatih/color"
"github.com/mattn/go-isatty"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func LogLevel(level string) zerolog.Level {
Expand Down Expand Up @@ -60,15 +62,9 @@ func LogFormat(out io.Writer, format string) io.Writer {
}

func InitLog(cmd *cobra.Command) {
level, err := cmd.Flags().GetString("log-level")
if err != nil {
panic(err)
}
level := viper.GetString(consts.LogLevelKey)
zerolog.SetGlobalLevel(LogLevel(level))

format, err := cmd.Flags().GetString("log-format")
if err != nil {
panic(err)
}
format := viper.GetString(consts.LogFormatKey)
log.Logger = log.Output(LogFormat(cmd.ErrOrStderr(), format))
}

0 comments on commit 48abba8

Please sign in to comment.