]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
ircbot.rb: ensure that the logger is flushed
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 20 Jun 2008 09:56:45 +0000 (11:56 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 20 Jun 2008 09:56:45 +0000 (11:56 +0200)
If the bot fails to load (e.g. because of missing dependency) the user
might miss the last error messages because the logger thread wouldn't
reach completion. Ensure its closure in an END block.

lib/rbot/ircbot.rb

index 33def8bc0892e2ac963d8e8cd5d5c7a5ac38e399..9aef8408276328771219e17cfee1bf53c4a1eace 100644 (file)
@@ -66,12 +66,18 @@ def rawlog(level, message=nil, who_pos=1)
   $log_queue.push qmsg
 end
 
-def restart_logger(newlogger = false)
+def halt_logger
   if $log_thread && $log_thread.alive?
     $log_queue << nil
     $log_thread.join
     $log_thread = nil
   end
+end
+
+END { halt_logger }
+
+def restart_logger(newlogger = false)
+  halt_logger
 
   $logger = newlogger if newlogger