fix: issue with logging not initializing correctly
This commit is contained in:
parent
e5c1b59bc1
commit
3244a66f8e
2 changed files with 34 additions and 16 deletions
20
cmd/root.go
20
cmd/root.go
|
|
@ -18,7 +18,7 @@ var (
|
|||
// plugins []string
|
||||
// timeout int
|
||||
// logFile string
|
||||
logLevel logger.LogLevel = logger.INFO
|
||||
loglevel logger.LogLevel = logger.INFO
|
||||
)
|
||||
|
||||
var rootCmd = cobra.Command{
|
||||
|
|
@ -32,7 +32,7 @@ var rootCmd = cobra.Command{
|
|||
|
||||
// initialize the logger
|
||||
logFile, _ = cmd.Flags().GetString("log-file")
|
||||
err = logger.InitWithLogLevel(logLevel, logFile)
|
||||
err = logger.InitWithLogLevel(loglevel, logFile)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to initialize logger")
|
||||
os.Exit(1)
|
||||
|
|
@ -67,8 +67,12 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(
|
||||
initLogger,
|
||||
// initializeConfig,
|
||||
)
|
||||
// initialize the config a single time
|
||||
rootCmd.PersistentFlags().VarP(&logLevel, "log-level", "l", "Set the log level output")
|
||||
rootCmd.PersistentFlags().VarP(&loglevel, "log-level", "l", "Set the log level output")
|
||||
rootCmd.PersistentFlags().String("log-file", "", "Set the log file path (can be set with MAKESHIFT_LOG_FILE)")
|
||||
}
|
||||
|
||||
|
|
@ -81,3 +85,13 @@ func setenv(cmd *cobra.Command, varname string, envvar string) {
|
|||
cmd.Flags().Set(varname, val)
|
||||
}
|
||||
}
|
||||
|
||||
func initLogger() {
|
||||
// initialize the logger
|
||||
logfile, _ := rootCmd.PersistentFlags().GetString("log-file")
|
||||
err := logger.InitWithLogLevel(loglevel, logfile)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to initialize logger")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue