diff --git a/changelog/15405.txt b/changelog/15405.txt new file mode 100644 index 000000000..eb9838633 --- /dev/null +++ b/changelog/15405.txt @@ -0,0 +1,3 @@ +```release-note:improvement +command: Support optional '-log-level' flag to be passed to 'operator migrate' command (defaults to info). Also support VAULT_LOG_LEVEL env var. +``` \ No newline at end of file diff --git a/command/agent.go b/command/agent.go index b48538956..883944da7 100644 --- a/command/agent.go +++ b/command/agent.go @@ -127,9 +127,9 @@ func (c *AgentCommand) Flags() *FlagSets { Target: &c.flagLogLevel, Default: "info", EnvVar: "VAULT_LOG_LEVEL", - Completion: complete.PredictSet("trace", "debug", "info", "warn", "err"), + Completion: complete.PredictSet("trace", "debug", "info", "warn", "error"), Usage: "Log verbosity level. Supported values (in order of detail) are " + - "\"trace\", \"debug\", \"info\", \"warn\", and \"err\".", + "\"trace\", \"debug\", \"info\", \"warn\", and \"error\".", }) f.BoolVar(&BoolVar{ diff --git a/command/operator_migrate.go b/command/operator_migrate.go index 1931584bc..5dcec8a56 100644 --- a/command/operator_migrate.go +++ b/command/operator_migrate.go @@ -11,6 +11,7 @@ import ( "time" log "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-secure-stdlib/strutil" "github.com/hashicorp/hcl" "github.com/hashicorp/hcl/hcl/ast" "github.com/hashicorp/vault/command/server" @@ -35,6 +36,7 @@ type OperatorMigrateCommand struct { PhysicalBackends map[string]physical.Factory flagConfig string + flagLogLevel string flagStart string flagReset bool logger log.Logger @@ -96,6 +98,16 @@ func (c *OperatorMigrateCommand) Flags() *FlagSets { Usage: "Reset the migration lock. No migration will occur.", }) + f.StringVar(&StringVar{ + Name: "log-level", + Target: &c.flagLogLevel, + Default: "info", + EnvVar: "VAULT_LOG_LEVEL", + Completion: complete.PredictSet("trace", "debug", "info", "warn", "error"), + Usage: "Log verbosity level. Supported values (in order of detail) are " + + "\"trace\", \"debug\", \"info\", \"warn\", and \"error\". These are not case sensitive.", + }) + return set } @@ -108,7 +120,6 @@ func (c *OperatorMigrateCommand) AutocompleteFlags() complete.Flags { } func (c *OperatorMigrateCommand) Run(args []string) int { - c.logger = logging.NewVaultLogger(log.Info) f := c.Flags() if err := f.Parse(args); err != nil { @@ -116,6 +127,14 @@ func (c *OperatorMigrateCommand) Run(args []string) int { return 1 } + c.flagLogLevel = strings.ToLower(c.flagLogLevel) + validLevels := []string{"trace", "debug", "info", "warn", "error"} + if !strutil.StrListContains(validLevels, c.flagLogLevel) { + c.UI.Error(fmt.Sprintf("%s is an unknown log level. Valid log levels are: %s", c.flagLogLevel, validLevels)) + return 1 + } + c.logger = logging.NewVaultLogger(log.LevelFromString(c.flagLogLevel)) + if c.flagConfig == "" { c.UI.Error("Must specify exactly one config path using -config") return 1 diff --git a/command/server.go b/command/server.go index b169e3805..9a0cdb77b 100644 --- a/command/server.go +++ b/command/server.go @@ -189,9 +189,9 @@ func (c *ServerCommand) Flags() *FlagSets { Target: &c.flagLogLevel, Default: notSetValue, EnvVar: "VAULT_LOG_LEVEL", - Completion: complete.PredictSet("trace", "debug", "info", "warn", "err"), + Completion: complete.PredictSet("trace", "debug", "info", "warn", "error"), Usage: "Log verbosity level. Supported values (in order of detail) are " + - "\"trace\", \"debug\", \"info\", \"warn\", and \"err\".", + "\"trace\", \"debug\", \"info\", \"warn\", and \"error\".", }) f.StringVar(&StringVar{