updateLogLevel sets the logger level based on the flag value
(cmd *cobra.Command)
| 96 | |
| 97 | // updateLogLevel sets the logger level based on the flag value |
| 98 | func updateLogLevel(cmd *cobra.Command) { |
| 99 | // Load configuration first |
| 100 | if err := cfgManager.LoadConfig(); err != nil { |
| 101 | logger.WithError(err).Warn("Failed to load config") |
| 102 | } |
| 103 | |
| 104 | // Check if the log-level flag was explicitly set |
| 105 | flagLogLevel := logLevel |
| 106 | if cmd.Flag("log-level").Changed { |
| 107 | // Flag was explicitly set, use it |
| 108 | level, err := logrus.ParseLevel(flagLogLevel) |
| 109 | if err != nil { |
| 110 | level = logrus.InfoLevel |
| 111 | } |
| 112 | logger.SetLevel(level) |
| 113 | cfgManager.GetConfig().LogLevel = flagLogLevel |
| 114 | } else { |
| 115 | // Flag was not set, use config file value if available |
| 116 | configLogLevel := cfgManager.GetConfig().LogLevel |
| 117 | if configLogLevel != "" { |
| 118 | level, err := logrus.ParseLevel(configLogLevel) |
| 119 | if err != nil { |
| 120 | level = logrus.InfoLevel |
| 121 | } |
| 122 | logger.SetLevel(level) |
| 123 | } else { |
| 124 | // No config value either, use default |
| 125 | logger.SetLevel(logrus.InfoLevel) |
| 126 | cfgManager.GetConfig().LogLevel = constants.LogLevelInfo |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // checkRoot ensures the command is run as root (Unix) or Administrator (Windows) |
| 132 | func checkRoot() error { |
no test coverage detected