diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-09 17:41:36 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-09 17:41:36 +0000 |
commit | 133c17fa6665256cafdcd1cf76d2ae50233c44f4 (patch) | |
tree | 1288ceef2c13826fea395a518cdb4fc806ca8ad6 /lib | |
parent | c3cc16274d2a2cc0b394bb7ec7fbb8b45491abcc (diff) | |
download | puppet-133c17fa6665256cafdcd1cf76d2ae50233c44f4.tar.gz puppet-133c17fa6665256cafdcd1cf76d2ae50233c44f4.tar.xz puppet-133c17fa6665256cafdcd1cf76d2ae50233c44f4.zip |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet.rb | 6 | ||||
-rw-r--r-- | lib/puppet/log.rb | 5 |
2 files changed, 11 insertions, 0 deletions
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) |