summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-04-06 10:20:25 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-04-06 10:20:25 -0700
commit4c01ebf6a35f221461c93bd915312f2703af8b29 (patch)
tree0c4257aba0dab4f421d7d68df03d244587ecc844
parentb2b87c35ceb2d6e05c2be2f381b3e3dbe86a3dd1 (diff)
downloadchef-4c01ebf6a35f221461c93bd915312f2703af8b29.tar.gz
Chef-13: restore log_location in client.rb
This was probably a bit too aggressive. There are people who pass logger objects in client.rb directly into the log_location, and we'd break them, and there's no general solution. We have a couple of the popular configs that can be passed in as symbols, but not the general case. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--RELEASE_NOTES.md13
-rw-r--r--lib/chef/application.rb15
-rw-r--r--lib/chef/application/windows_service.rb17
3 files changed, 31 insertions, 14 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index ac49fd7edc..fb6d4a8d97 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -280,21 +280,8 @@ is sent to a pipe. The logger needs to be specifically requested with `--force-
The `--force-formatter` option does still exist, although it will probably be deprecated in the future.
-Setting the `log_location` in the config.rb now applies to both daemonized and command-line invocation and there is
-no magic which dups the logger in order to log to STDOUT on the command line in that case.
-
-Setting logger settings in config.rb is most likely no longer appropriate and those settings should be changed to
-command line flags on the config script or cronjob that invokes chef-client daemonized. In other words:
-
-```
-chef-client -d -L /var/log/client.rb --force-logger
-```
-
If your logfiles switch to the formatter, you need to include `--force-logger` for your daemonized runs.
-If your command line invocations have no output, delete the config.rb setting for the log_location and move that
-to the command line that invokes your daemon process.
-
Redirecting output to a file with `chef-client > /tmp/chef.out` now captures the same output as invoking it directly on the command
line with no redirection.
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