diff --git a/.changelog/15625.txt b/.changelog/15625.txt new file mode 100644 index 00000000000..2e5e82668ee --- /dev/null +++ b/.changelog/15625.txt @@ -0,0 +1,3 @@ +```release-note:bug +agent: Make agent syslog log level follow log_level config +``` diff --git a/command/agent/command.go b/command/agent/command.go index b2bcbeaa7cd..c16bbd242c0 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -472,10 +472,21 @@ func SetupLoggers(ui cli.Ui, config *Config) (*logutils.LevelFilter, *gatedwrite // Create a log writer, and wrap a logOutput around it writers := []io.Writer{logFilter} - + logLevel := strings.ToUpper(config.LogLevel) + logLevelMap := map[string]gsyslog.Priority{ + "ERROR": gsyslog.LOG_ERR, + "WARN": gsyslog.LOG_WARNING, + "INFO": gsyslog.LOG_INFO, + "DEBUG": gsyslog.LOG_DEBUG, + "TRACE": gsyslog.LOG_DEBUG, + } + if logLevel == "OFF" { + config.EnableSyslog = false + } // Check if syslog is enabled if config.EnableSyslog { - l, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, config.SyslogFacility, "nomad") + ui.Output(fmt.Sprintf("Config enable_syslog is `true` with log_level=%v", config.LogLevel)) + l, err := gsyslog.NewLogger(logLevelMap[logLevel], config.SyslogFacility, "nomad") if err != nil { ui.Error(fmt.Sprintf("Syslog setup failed: %v", err)) return nil, nil, nil diff --git a/website/content/docs/configuration/index.mdx b/website/content/docs/configuration/index.mdx index 2b1d5ee00a1..423309eaf44 100644 --- a/website/content/docs/configuration/index.mdx +++ b/website/content/docs/configuration/index.mdx @@ -165,7 +165,8 @@ testing. diagnostic information about Nomad's internals. - `enable_syslog` `(bool: false)` - Specifies if the agent should log to syslog. - This option only works on Unix based systems. + This option only works on Unix based systems. The log level inherits from + the Nomad agent log set in `log_level` - `http_api_response_headers` `(map: nil)` - Specifies user-defined headers to add to the HTTP API responses.