summaryrefslogtreecommitdiff
path: root/lib/chef/config.rb
diff options
context:
space:
mode:
authorNikhil Benesch <nikhil.benesch@gmail.com>2014-01-13 00:00:31 -0500
committerdanielsdeleo <dan@opscode.com>2014-01-20 16:58:41 -0800
commit6a4b9a7849f4c60fdd2b016b288e01f2a6fd03f2 (patch)
tree3bab09fd5bd64cfc24f0f3573dbe54fef2f41bc5 /lib/chef/config.rb
parente15f04b1ed124767a04ef4f5de4f8678fcbe33df (diff)
downloadchef-6a4b9a7849f4c60fdd2b016b288e01f2a6fd03f2.tar.gz
CHEF-4725: Validate 'log_location' setting on log initialization
Previously, a Mixlib::Config setter method verified that 'log_location' was set to a writeable file or a valid IO stream. Due to the way Mixlib::Config handles `default` and `merge!`, this setter method would not fire if the 'log_location' was left unconfigured or if it was set on the command line, resulting in inconsistent error handling. This commit moves the validation logic out of the configuration layer and into the log initializion layer. This ensures that error handling is consistent, regardless of where the 'log_location' setting is configured. Validation logic is also simplified, relying on the MonoLogger class to open and configure any necessary IO streams.
Diffstat (limited to 'lib/chef/config.rb')
-rw-r--r--lib/chef/config.rb24
1 files changed, 3 insertions, 21 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index f8bfa3ac21..f5cba9e0ed 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -127,26 +127,6 @@ class Chef
# properly.
configurable(:daemonize).writes_value { |v| v }
- # Override the config dispatch to set the value of log_location configuration option
- #
- # === Parameters
- # location<IO||String>:: Logging location as either an IO stream or string representing log file path
- #
- config_attr_writer :log_location do |location|
- if location.respond_to? :sync=
- location.sync = true
- location
- elsif location.respond_to? :to_str
- begin
- f = File.new(location.to_str, "a")
- f.sync = true
- rescue Errno::ENOENT
- raise Chef::Exceptions::ConfigurationError, "Failed to open or create log file at #{location.to_str}"
- end
- f
- end
- end
-
# The root where all local chef object data is stored. cookbooks, data bags,
# environments are all assumed to be in separate directories under this.
# chef-solo uses these directories for input data. knife commands
@@ -299,6 +279,9 @@ class Chef
# logger is the primary mode of output, and the log level is set to :info
default :log_level, :auto
+ # Logging location as either an IO stream or string representing log file path
+ default :log_location, STDOUT
+
# Using `force_formatter` causes chef to default to formatter output when STDOUT is not a tty
default :force_formatter, false
@@ -310,7 +293,6 @@ class Chef
default :interval, nil
default :once, nil
default :json_attribs, nil
- default :log_location, STDOUT
# toggle info level log items that can create a lot of output
default :verbose_logging, true
default :node_name, nil