diff options
Diffstat (limited to 'lib/chef/application.rb')
-rw-r--r-- | lib/chef/application.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index 005418d184..096ce9c392 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -150,6 +150,9 @@ class Chef def configure_logging configure_log_location Chef::Log.init(MonoLogger.new(Chef::Config[:log_location])) + if want_additional_logger? + configure_stdout_logger + end Chef::Log.level = resolve_log_level rescue StandardError => error Chef::Log.fatal("Failed to open or create log file at #{Chef::Config[:log_location]}: #{error.class} (#{error.message})") @@ -170,6 +173,18 @@ class Chef end 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] + end + + def configure_stdout_logger + stdout_logger = MonoLogger.new(STDOUT) + stdout_logger.formatter = Chef::Log.logger.formatter + Chef::Log.loggers << stdout_logger + 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] |