Behaviour is now:

If logdest is specified on the command line this wins
If setdest (for example running --no-daemonize) then this wins
If neither is set then Puppet checks the logdest option in puppet.conf
This defaults to syslog meaning current behaviour is unchanged.

I've also added and made the logging behavious and setup consistent
between the master, agent, apply and inspect.

Signed-off-by: James Turnbull <[email protected]>
---
 lib/puppet/application/agent.rb     |   15 +++++++++++----
 lib/puppet/application/apply.rb     |    4 ++--
 lib/puppet/application/inspect.rb   |    4 ++--
 lib/puppet/application/master.rb    |    7 +++++--
 lib/puppet/defaults.rb              |    5 ++++-
 lib/puppet/util/run_mode.rb         |    7 +++++++
 spec/unit/application/apply_spec.rb |    4 ++--
 spec/unit/util/run_mode_spec.rb     |    7 +++++++
 8 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 2b75505..609ee61 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -67,8 +67,8 @@ class Puppet::Application::Agent < Puppet::Application
 
   option("--logdest DEST", "-l DEST") do |arg|
     begin
+      options[:logdest] = true
       Puppet::Util::Log.newdestination(arg)
-      options[:setdest] = true
     rescue => detail
       puts detail.backtrace if Puppet[:debug]
       $stderr.puts detail.to_s
@@ -147,15 +147,22 @@ class Puppet::Application::Agent < Puppet::Application
   # Handle the logging settings.
   def setup_logs
     if options[:debug] or options[:verbose]
-      Puppet::Util::Log.newdestination(:console)
       if options[:debug]
         Puppet::Util::Log.level = :debug
       else
         Puppet::Util::Log.level = :info
       end
+      
+      unless Puppet[:daemonize]
+        Puppet::Util::Log.newdestination(:console)
+        options[:setdest] = true
+      end 
+    end 
+
+    # Use the logdest configuration option unless specified
+    unless options[:logdest] || options[:setdest]
+      Puppet::Util::Log.newdestination(Puppet.settings[:logdest])
     end
-
-    Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
   end
 
   def enable_disable_client(agent)
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 33a70ce..9a36aab 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -20,7 +20,7 @@ class Puppet::Application::Apply < Puppet::Application
   option("--logdest LOGDEST", "-l") do |arg|
     begin
       Puppet::Util::Log.newdestination(arg)
-      options[:logset] = true
+      options[:logdest] = true
     rescue => detail
       $stderr.puts detail.to_s
     end
@@ -139,7 +139,7 @@ class Puppet::Application::Apply < Puppet::Application
     # If noop is set, then also enable diffs
     Puppet[:show_diff] = true if Puppet[:noop]
 
-    Puppet::Util::Log.newdestination(:console) unless options[:logset]
+    Puppet::Util::Log.newdestination(:console) unless options[:logdest]
     client = nil
     server = nil
 
diff --git a/lib/puppet/application/inspect.rb 
b/lib/puppet/application/inspect.rb
index c7be893..96b609a 100644
--- a/lib/puppet/application/inspect.rb
+++ b/lib/puppet/application/inspect.rb
@@ -10,8 +10,8 @@ class Puppet::Application::Inspect < Puppet::Application
 
   option("--logdest LOGDEST", "-l") do |arg|
     begin
+      options[:logdest] = true
       Puppet::Util::Log.newdestination(arg)
-      options[:logset] = true
     rescue => detail
       $stderr.puts detail.to_s
     end
@@ -25,7 +25,7 @@ class Puppet::Application::Inspect < Puppet::Application
     @report = Puppet::Transaction::Report.new("inspect")
 
     Puppet::Util::Log.newdestination(@report)
-    Puppet::Util::Log.newdestination(:console) unless options[:logset]
+    Puppet::Util::Log.newdestination(:console) unless options[:logdest]
 
     trap(:INT) do
       $stderr.puts "Exiting"
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index fde4749..d296dfc 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -17,8 +17,8 @@ class Puppet::Application::Master < Puppet::Application
 
   option("--logdest DEST",  "-l DEST") do |arg|
     begin
+      options[:logdest] = true
       Puppet::Util::Log.newdestination(arg)
-      options[:setdest] = true
     rescue => detail
       puts detail.backtrace if Puppet[:debug]
       $stderr.puts detail.to_s
@@ -132,7 +132,10 @@ class Puppet::Application::Master < Puppet::Application
       end
     end
 
-    Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
+    # Use the logdest configuration option unless specified
+    unless options[:setdest] || options[:logdest]
+      Puppet::Util::Log.newdestination(Puppet.settings[:logdest])
+    end
 
     exit(Puppet.settings.print_configs ? 0 : 1) if 
Puppet.settings.print_configs?
 
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 5002893..59b1e89 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -10,7 +10,10 @@ module Puppet
     :run_mode => [Puppet.run_mode.name.to_s, "The effective 'run mode' of the 
application: master, agent, or user."]
   )
 
-  setdefaults(:main, :logdir => Puppet.run_mode.log_dir)
+  setdefaults(:main,
+    :logdir => Puppet.run_mode.log_dir,
+    :logdest => Puppet.run_mode.log_dest
+  )
 
   setdefaults(:main,
     :trace => [false, "Whether to print stack traces on some errors"],
diff --git a/lib/puppet/util/run_mode.rb b/lib/puppet/util/run_mode.rb
index a7e7b04..446ccd7 100644
--- a/lib/puppet/util/run_mode.rb
+++ b/lib/puppet/util/run_mode.rb
@@ -57,6 +57,13 @@ module Puppet
         end
       end
 
+      def log_dest
+        {
+          :default => "syslog",
+          :desc => "The default Puppet log destination."
+        }
+      end
+
       private
 
       def which_dir( global, user )
diff --git a/spec/unit/application/apply_spec.rb 
b/spec/unit/application/apply_spec.rb
index 4e17442..59ba8eb 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -41,8 +41,8 @@ describe Puppet::Application::Apply do
       @apply.handle_logdest("console")
     end
 
-    it "should put the logset options to true" do
-      @apply.options.expects(:[]=).with(:logset,true)
+    it "should put the logdest option to true" do
+      @apply.options.expects(:[]=).with(:logdest,true)
 
       @apply.handle_logdest("console")
     end
diff --git a/spec/unit/util/run_mode_spec.rb b/spec/unit/util/run_mode_spec.rb
index 1ce1aa0..8287316 100644
--- a/spec/unit/util/run_mode_spec.rb
+++ b/spec/unit/util/run_mode_spec.rb
@@ -48,4 +48,11 @@ describe Puppet::Util::RunMode do
       :desc    => "The Puppet log directory.",
     }
   end
+
+  it "should have log_dest return a hash with syslog and other metadata" do
+    @run_mode.log_dest.should == {
+      :default => "syslog",
+      :desc    => "The default Puppet log destination."
+    }   
+  end 
 end
-- 
1.7.3.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to