From faaa2c11f0b1420cef0c48c0d6b2067a1987fc23 Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Wed, 8 Feb 2023 14:55:43 -0600 Subject: [PATCH] command: Fix logger not initializing properly in envoy command (#16148) (#16153) Co-authored-by: Kyle Havlovitz --- command/connect/envoy/envoy.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/command/connect/envoy/envoy.go b/command/connect/envoy/envoy.go index 9fc86508eb..d239648348 100644 --- a/command/connect/envoy/envoy.go +++ b/command/connect/envoy/envoy.go @@ -220,12 +220,6 @@ func (c *cmd) init() { flags.Merge(c.flags, c.http.ClientFlags()) flags.Merge(c.flags, c.http.MultiTenancyFlags()) c.help = flags.Usage(help, c.flags) - - opts := hclog.LoggerOptions{Level: hclog.Off} - if c.enableLogging { - opts.Level = hclog.Debug - } - c.logger = hclog.New(&opts) } // canBindInternal is here mainly so we can unit test this with a constant net.Addr list @@ -278,13 +272,18 @@ func (c *cmd) Run(args []string) int { c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err)) return 1 } - c.logger.Debug("Initialized API client") // TODO: refactor return c.run(c.flags.Args()) } func (c *cmd) run(args []string) int { + opts := hclog.LoggerOptions{Level: hclog.Off} + if c.enableLogging { + opts.Level = hclog.Debug + } + c.logger = hclog.New(&opts) + c.logger.Debug("Starting Envoy config generation") if c.nodeName != "" && c.proxyID == "" { c.UI.Error("'-node-name' requires '-proxy-id'")