diff options
author | sersut <serdar@opscode.com> | 2013-02-20 15:26:08 -0800 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2013-02-20 15:26:08 -0800 |
commit | c20b0324b0b2e162ce95584bef685d112bf7201d (patch) | |
tree | d567a26f7b0537012ae6600fac89fa6aa0452b50 | |
parent | a42583a5b691c3b41ccac941b7bc948aa4ea28cd (diff) | |
download | chef-c20b0324b0b2e162ce95584bef685d112bf7201d.tar.gz |
Bring over the new logger initialization logic form application.rb.
-rw-r--r-- | lib/chef/application/windows_service.rb | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 5ece03b3a8..d3493d8a47 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -191,16 +191,52 @@ class Chef Chef::Config[:interval] ||= 1800 end - # Lifted from Chef::Application and Chef::Application::Client - # MUST BE RUN AFTER configuration has been parsed! + # Lifted from application.rb + # See application.rb for related comments. + def configure_logging - # Implementation from Chef::Application Chef::Log.init(Chef::Config[:log_location]) - Chef::Log.level = Chef::Config[:log_level] + if want_additional_logger? + configure_stdout_logger + end + Chef::Log.level = resolve_log_level + end + + def configure_stdout_logger + stdout_logger = Logger.new(STDOUT) + STDOUT.sync = true + stdout_logger.formatter = Chef::Log.logger.formatter + Chef::Log.loggers << stdout_logger + end + + # Based on config and whether or not STDOUT is a tty, should we setup a + # secondary logger for stdout? + def want_additional_logger? + ( Chef::Config[:log_location] != STDOUT ) && STDOUT.tty? && (!Chef::Config[:daemonize]) && (Chef::Config[:force_logger]) + end - # Implementation from Chef::Application::Client - Mixlib::Authentication::Log.use_log_devices( Chef::Log ) - Ohai::Log.use_log_devices( Chef::Log ) + # Use of output formatters is assumed if `force_formatter` is set or if + # `force_logger` is not set and STDOUT is to a console (tty) + def using_output_formatter? + Chef::Config[:force_formatter] || (!Chef::Config[:force_logger] && STDOUT.tty?) + end + + def auto_log_level? + Chef::Config[:log_level] == :auto + end + + # if log_level is `:auto`, convert it to :warn (when using output formatter) + # or :info (no output formatter). See also +using_output_formatter?+ + def resolve_log_level + if auto_log_level? + if using_output_formatter? + :warn + else + :info + end + else + Chef::Config[:log_level] + end end def configure_chef(startup_parameters) |