Skip to content

Commit

Permalink
Added optional -log-level flag to 'operator migrate' command (#15405)
Browse files Browse the repository at this point in the history
  • Loading branch information
peteski22 authored May 12, 2022
1 parent 7aaa70c commit aa2a10a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog/15405.txt
Original file line number Diff line number Diff line change
@@ -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.
```
4 changes: 2 additions & 2 deletions command/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
21 changes: 20 additions & 1 deletion command/operator_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,6 +36,7 @@ type OperatorMigrateCommand struct {

PhysicalBackends map[string]physical.Factory
flagConfig string
flagLogLevel string
flagStart string
flagReset bool
logger log.Logger
Expand Down Expand Up @@ -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
}

Expand All @@ -108,14 +120,21 @@ 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 {
c.UI.Error(err.Error())
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
Expand Down
4 changes: 2 additions & 2 deletions command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit aa2a10a

Please sign in to comment.