summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-07-01 16:58:16 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-07-01 17:08:07 -0700
commita989224f97489d1286d7b67c0c00d55c225e3f09 (patch)
treee8c507437ec3c1a8775cae4073a6f1c2a2b04411
parent93cb2accdb53a48981527c576d44604ffaee8f64 (diff)
downloadchef-a989224f97489d1286d7b67c0c00d55c225e3f09.tar.gz
Fix syslog logging on Chef-16
This forces the formatter output off for users that use the winevt or syslog options to the log_location. This changes nothing about the logging behavior from Chef-15, those never supported formatter output. It creates some more clear consistency with how STDOUT behaves when those options are used. - We do not have the ability (fairly fundamentally in the Chef::Log class itself) to have different log levels running at the same time so either you get :warn or you get :info and we'll likely never be able to support mix-and-match. - Without mix-and-match if you're trying to use the formatter on STDOUT the syslog logger you have to either pick :warn -- which makes the syslog output totally useless, or else pick :info -- which intersperses all of the info logger output with the formatter on STDOUT and leads to complaints and bug reports. - So we force the logger on, although users can still get the old STDOUT logging behavior back with --force-formatter -l info Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/application.rb12
-rw-r--r--lib/chef/client.rb2
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 0d80123bda..1e3b72e1ad 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -194,8 +194,10 @@ class Chef
chef_config[:log_location].map! do |log_location|
case log_location
when :syslog, "syslog"
+ force_force_logger
logger::Syslog.new
when :win_evt, "win_evt"
+ force_force_logger
logger::WinEvt.new
else
# should be a path or STDOUT
@@ -204,6 +206,16 @@ class Chef
end
end
+ # Force the logger by default for the :winevt and :syslog loggers. Since we do not and cannot
+ # support multiple log levels in a mix-and-match situation with formatters and loggers, and the
+ # formatters do not support syslog, we force the formatter off by default and the log level is
+ # thus info by default. Users can add `--force-formatter -l info` to get back formatter output
+ # on STDOUT along with syslog logging.
+ #
+ def force_force_logger
+ chef_config[:force_logger] = true unless chef_config[:force_formatter]
+ end
+
# Use of output formatters is assumed if `force_formatter` is set or if `force_logger` is not set
def using_output_formatter?
chef_config[:force_formatter] || !chef_config[:force_logger]
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index a43740258d..b6f9958d64 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -343,7 +343,7 @@ class Chef
formatters_for_run.map do |formatter_name, output_path|
if output_path.nil?
Chef::Formatters.new(formatter_name, STDOUT_FD, STDERR_FD)
- else
+ elsif output_path.is_a?(String)
io = File.open(output_path, "a+")
io.sync = true
Chef::Formatters.new(formatter_name, io, io)