diff options
author | Thom May <thom@may.lt> | 2017-04-06 21:46:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-06 21:46:37 +0100 |
commit | b8afdc5630ebe502beadf214b9ca0abc1c98c43b (patch) | |
tree | d15b1b2a25bf46820f1bc1e7a78f0ecbe2f1e81d /lib | |
parent | 30e95f165f0b58464e4bf7df736d3fa4b21d1c4e (diff) | |
parent | 0029b194433491c163d40d4134d306d47c8d0632 (diff) | |
download | chef-b8afdc5630ebe502beadf214b9ca0abc1c98c43b.tar.gz |
Merge pull request #6035 from chef/lcg/restore-log-location
Chef-13: restore log_location in client.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/application.rb | 15 | ||||
-rw-r--r-- | lib/chef/application/windows_service.rb | 17 |
2 files changed, 31 insertions, 1 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] diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 5e95c14095..fa4b3fd27e 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -241,11 +241,26 @@ class Chef def configure_logging Chef::Log.init(MonoLogger.new(resolve_log_location)) + if want_additional_logger? + configure_stdout_logger + end Chef::Log.level = resolve_log_level end + def configure_stdout_logger + stdout_logger = MonoLogger.new(STDOUT) + 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] + end + # 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) + # `force_logger` is not set def using_output_formatter? Chef::Config[:force_formatter] || !Chef::Config[:force_logger] end |