Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow log level to be specified in an env var #3721

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ type ServerCommand struct {
func (c *ServerCommand) Run(args []string) int {
var dev, verifyOnly, devHA, devTransactional, devLeasedKV, devThreeNode, devSkipInit bool
var configPath []string
var logLevel, devRootTokenID, devListenAddress, devPluginDir string
var logLevelFlag, devRootTokenID, devListenAddress, devPluginDir string
var devLatency, devLatencyJitter int
flags := c.Meta.FlagSet("server", meta.FlagSetDefault)
flags.BoolVar(&dev, "dev", false, "")
flags.StringVar(&devRootTokenID, "dev-root-token-id", "", "")
flags.StringVar(&devListenAddress, "dev-listen-address", "", "")
flags.StringVar(&devPluginDir, "dev-plugin-dir", "", "")
flags.StringVar(&logLevel, "log-level", "info", "")
flags.StringVar(&logLevelFlag, "log-level", "", "")
flags.IntVar(&devLatency, "dev-latency", 0, "")
flags.IntVar(&devLatencyJitter, "dev-latency-jitter", 20, "")
flags.BoolVar(&verifyOnly, "verify-only", false, "")
Expand All @@ -100,19 +100,25 @@ func (c *ServerCommand) Run(args []string) int {
// start logging too early.
c.logGate = &gatedwriter.Writer{Writer: colorable.NewColorable(os.Stderr)}
var level int
logLevel = strings.ToLower(strings.TrimSpace(logLevel))
var logLevel string
if os.Getenv("VAULT_LOG_LEVEL") != "" {
logLevel = os.Getenv("VAULT_LOG_LEVEL")
}
if logLevelFlag != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally env vars take precedence over config values, think this should too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a config value, it's a flag -- which generally takes precedence over env vars :-)

logLevel = strings.ToLower(strings.TrimSpace(logLevelFlag))
}
switch logLevel {
case "trace":
level = log.LevelTrace
case "debug":
level = log.LevelDebug
case "info":
case "info", "":
level = log.LevelInfo
case "notice":
level = log.LevelNotice
case "warn":
case "warn", "warning":
level = log.LevelWarn
case "err":
case "err", "error":
level = log.LevelError
default:
c.Ui.Output(fmt.Sprintf("Unknown log level %s", logLevel))
Expand Down Expand Up @@ -1278,7 +1284,8 @@ General Options:

-log-level=info Log verbosity. Defaults to "info", will be output to
stderr. Supported values: "trace", "debug", "info",
"warn", "err"
"warn", "err". Can also be specified with the
VAULT_LOG_LEVEL environment variable.
`
return strings.TrimSpace(helpText)
}
Expand Down