Please review pull request #668: (#13929) Improve logging for very early failures opened by (cprice-puppet)

Description:

This adds a "force_flushqueue" method to the Log class.
This can be called prior to a system exit, to force
any queued log messages to be flushed. If no
logging destinations have been configured it will
attempt to create a console destination for the
queue to be flushed to.

  • Opened: Thu Apr 12 23:05:15 UTC 2012
  • Based on: puppetlabs:master (e8d8d6879cf54881bba1f6887162b78b7ab3c7bb)
  • Requested merge: cprice-puppet:bug/master/13929-exit-on-fail-logging (03bf1a69d215c71e123bbacfe762afb1908bb035)

Diff follows:

diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 4cfa793..6eb154a 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -504,6 +504,7 @@ def exit_on_fail(message, code = 1)
   #  code (e.g. webrick), and we have no idea what they might throw.
   rescue Exception => err
     Puppet.log_exception(err, "Could not #{message}: #{err}")
+    Puppet::Util::Log.force_flushqueue()
     exit(code)
   end
   module_function :exit_on_fail
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index cb664a9..e9607cf 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -170,6 +170,20 @@ def Log.flushqueue
     @queued.clear
   end
 
+  # Flush the logging queue.  If there are no destinations available,
+  #  adds in a console logger before flushing the queue.
+  # This is mainly intended to be used as a last-resort attempt
+  #  to ensure that logging messages are not thrown away before
+  #  the program is about to exit--most likely in a horrific
+  #  error scenario.
+  # @return nil
+  def Log.force_flushqueue()
+    if (@destinations.empty? and !(@queued.empty?))
+      newdestination(:console)
+    end
+    flushqueue
+  end
+
   def Log.sendlevel?(level)
     @levels.index(level) >= @loglevel
   end

    

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

Reply via email to