From 133c17fa6665256cafdcd1cf76d2ae50233c44f4 Mon Sep 17 00:00:00 2001 From: luke Date: Mon, 9 Oct 2006 17:41:36 +0000 Subject: Fixing #305 -- logs now reopen when Puppet restarts, and there is also now an autoflush mechanism available so logs will flush to disk immediately. I also now trap USR2 and reopen logs when it is sent, so if you just want to reopen logs you do not have to restart the whole process. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1750 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet.rb | 6 ++++++ lib/puppet/log.rb | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'lib') diff --git a/lib/puppet.rb b/lib/puppet.rb index b0b3bbea9..a0e382e57 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -107,6 +107,7 @@ module Puppet self.setdefaults(:puppet, :trace => [false, "Whether to print stack traces on some errors"], + :autoflush => [false, "Whether log files should always flush to disk."], :syslogfacility => ["daemon", "What syslog facility to use when logging to syslog. Syslog has a fixed list of valid facilities, and you must choose one of those; you cannot just make one up."], @@ -341,6 +342,7 @@ module Puppet command = $0 + " " + self.args.join(" ") Puppet.notice "Restarting with '%s'" % command Puppet.shutdown(false) + Puppet::Log.reopen exec(command) end @@ -389,6 +391,10 @@ module Puppet Puppet.notice "No clients were run" end end + + trap(:USR2) do + Puppet::Log.reopen + end end # Shutdown our server process, meaning stop all services and all threads. diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb index c8d92e649..c76dd945c 100644 --- a/lib/puppet/log.rb +++ b/lib/puppet/log.rb @@ -237,11 +237,15 @@ module Puppet file = File.open(path, File::WRONLY|File::CREAT|File::APPEND) @file = file + + @autoflush = Puppet[:autoflush] end def handle(msg) @file.puts("%s %s (%s): %s" % [msg.time, msg.source, msg.level, msg.to_s]) + + @file.flush if @autoflush end end @@ -411,6 +415,7 @@ module Puppet # Reopen all of our logs. def Log.reopen + Puppet.notice "Reopening log files" types = @destinations.keys @destinations.each { |type, dest| if dest.respond_to?(:close) -- cgit