diff options
author | dmitry kim <jason@nichego.net> | 2008-04-16 01:06:28 +0400 |
---|---|---|
committer | dmitry kim <jason@nichego.net> | 2008-04-16 01:06:56 +0400 |
commit | dd87231af22d1a94562b1c6b312c8af97d258bfb (patch) | |
tree | 7bea63ae63427284623cbce27ee1118f5db802af /lib/rbot/ircbot.rb | |
parent | e86335936a37b372cbdff4b106ba32aff0a0e9dc (diff) |
* ircbot logging: fixed the logger thread wrt daemonizing
Diffstat (limited to 'lib/rbot/ircbot.rb')
-rw-r--r-- | lib/rbot/ircbot.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 4dcc91fc..057170b8 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -19,12 +19,7 @@ $logger.level = $cl_loglevel if defined? $cl_loglevel $logger.level = 0 if $debug $log_queue = Queue.new -Thread.new do - ls = nil - while ls = $log_queue.pop - ls.each { |l| $logger.add(*l) } - end -end +$log_thread = nil require 'pp' @@ -71,8 +66,26 @@ def rawlog(level, message=nil, who_pos=1) $log_queue.push qmsg end +def restart_logger + if $log_thread && $log_thread.alive? + $log_queue << nil + $log_thread.join + $log_thread = nil + end + + $log_thread = Thread.new do + ls = nil + while ls = $log_queue.pop + ls.each { |l| $logger.add(*l) } + end + end +end + +restart_logger + def log_session_start $logger << "\n\n=== #{botclass} session started on #{Time.now.strftime($dateformat)} ===\n\n" + restart_logger end def log_session_end |