From 63ea13be778092be2d4d606675254912451a78bf Mon Sep 17 00:00:00 2001 From: James Rasell Date: Fri, 17 Jan 2025 14:47:06 +0100 Subject: [PATCH] agent: Ensure logger set up method is public. (#24886) This is needed by a Nomad Enterprise code path. --- command/agent/command.go | 9 ++++++--- command/agent/command_test.go | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index cb403d36090..4b396efa418 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -549,8 +549,11 @@ func (c *Command) IsValidConfig(config, cmdConfig *Config) bool { return true } -// setupLoggers is used to set up the logGate and our logOutput. -func setupLoggers(ui cli.Ui, config *Config) (*gatedwriter.Writer, io.Writer) { +// SetupLoggers is used to set up the logGate and our logOutput. +// +// The function needs to be public due to the way it is used within the Nomad +// Enterprise codebase. +func SetupLoggers(ui cli.Ui, config *Config) (*gatedwriter.Writer, io.Writer) { // Pull the log level from the configuration, ensure it is titled and then // perform validation. Do this before the gated writer, as this can @@ -801,7 +804,7 @@ func (c *Command) Run(args []string) int { } // Set up the log outputs. - logGate, logOutput := setupLoggers(c.Ui, config) + logGate, logOutput := SetupLoggers(c.Ui, config) if logGate == nil { return 1 } diff --git a/command/agent/command_test.go b/command/agent/command_test.go index ccdf06357f3..dc3620b9eee 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -639,7 +639,7 @@ func Test_setupLoggers_logFile(t *testing.T) { } // Generate the loggers and ensure the correct error is generated. - gatedWriter, writer := setupLoggers(mockUI, cfg) + gatedWriter, writer := SetupLoggers(mockUI, cfg) must.Nil(t, gatedWriter) must.Nil(t, writer) must.StrContains(t, mockUI.ErrorWriter.String(), "Invalid log level: WARNING") @@ -650,7 +650,7 @@ func Test_setupLoggers_logFile(t *testing.T) { // Update the log level, so that it is a valid option and set up the // loggers again. cfg.LogLevel = "warn" - gatedWriter, writer = setupLoggers(mockUI, cfg) + gatedWriter, writer = SetupLoggers(mockUI, cfg) must.NotNil(t, gatedWriter) must.NotNil(t, writer)