From 57b6b742838f117460d538359c3f6382d1e7dab5 Mon Sep 17 00:00:00 2001 From: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com> Date: Mon, 11 Dec 2023 08:08:48 -0800 Subject: [PATCH] release log gate if disable-gated-logs flag is set (#24280) * release log gate if disable-gated-logs flag is set * CL * Update changelog/24280.txt Co-authored-by: Josh Black --------- Co-authored-by: Peter Wilson Co-authored-by: Josh Black --- changelog/24280.txt | 3 +++ command/agent.go | 5 +++++ command/commands.go | 2 ++ command/log_flags.go | 8 ++++++++ command/proxy.go | 5 +++++ command/server.go | 5 +++++ 6 files changed, 28 insertions(+) create mode 100644 changelog/24280.txt diff --git a/changelog/24280.txt b/changelog/24280.txt new file mode 100644 index 0000000000..dd3c42fe4c --- /dev/null +++ b/changelog/24280.txt @@ -0,0 +1,3 @@ +```release-note:improvement +command/server: display logs on startup immediately if disable-gated-logs flag is set +``` diff --git a/command/agent.go b/command/agent.go index a3d46a32ed..613fccf426 100644 --- a/command/agent.go +++ b/command/agent.go @@ -222,6 +222,11 @@ func (c *AgentCommand) Run(args []string) int { InferLevelsWithTimestamp: true, }) + // release log gate if the disable-gated-logs flag is set + if c.logFlags.flagDisableGatedLogs { + c.logGate.Flush() + } + infoKeys := make([]string, 0, 10) info := make(map[string]string) info["log level"] = config.LogLevel diff --git a/command/commands.go b/command/commands.go index aac2d57bc7..e39d1a9ddc 100644 --- a/command/commands.go +++ b/command/commands.go @@ -148,6 +148,8 @@ const ( flagNameDisableRedirects = "disable-redirects" // flagNameCombineLogs is used to specify whether log output should be combined and sent to stdout flagNameCombineLogs = "combine-logs" + // flagDisableGatedLogs is used to disable gated logs and immediately show the vault logs as they become available + flagDisableGatedLogs = "disable-gated-logs" // flagNameLogFile is used to specify the path to the log file that Vault should use for logging flagNameLogFile = "log-file" // flagNameLogRotateBytes is the flag used to specify the number of bytes a log file should be before it is rotated. diff --git a/command/log_flags.go b/command/log_flags.go index 684b5aa018..cbde95d330 100644 --- a/command/log_flags.go +++ b/command/log_flags.go @@ -15,6 +15,7 @@ import ( // logFlags are the 'log' related flags that can be shared across commands. type logFlags struct { flagCombineLogs bool + flagDisableGatedLogs bool flagLogLevel string flagLogFormat string flagLogFile string @@ -41,6 +42,13 @@ func (f *FlagSet) addLogFlags(l *logFlags) { Hidden: true, }) + f.BoolVar(&BoolVar{ + Name: flagDisableGatedLogs, + Target: &l.flagDisableGatedLogs, + Default: false, + Hidden: true, + }) + f.StringVar(&StringVar{ Name: flagNameLogLevel, Target: &l.flagLogLevel, diff --git a/command/proxy.go b/command/proxy.go index 89cc77d983..90382eaae9 100644 --- a/command/proxy.go +++ b/command/proxy.go @@ -210,6 +210,11 @@ func (c *ProxyCommand) Run(args []string) int { } c.logger = l + // release log gate if the disable-gated-logs flag is set + if c.logFlags.flagDisableGatedLogs { + c.logGate.Flush() + } + infoKeys := make([]string, 0, 10) info := make(map[string]string) info["log level"] = config.LogLevel diff --git a/command/server.go b/command/server.go index 3b6d794ada..d3c6321c62 100644 --- a/command/server.go +++ b/command/server.go @@ -1104,6 +1104,11 @@ func (c *ServerCommand) Run(args []string) int { c.logger = l c.allLoggers = append(c.allLoggers, l) + // flush logs right away if the server is started with the disable-gated-logs flag + if c.logFlags.flagDisableGatedLogs { + c.flushLog() + } + // reporting Errors found in the config for _, cErr := range configErrors { c.logger.Warn(cErr.String())