diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/ircbot.rb | 9 | ||||
-rw-r--r-- | lib/rbot/logger.rb | 14 |
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index ecb48449..4eac68d6 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -403,6 +403,8 @@ class Bot debug "Using `#{@logfile}' as debug log" end + LoggerManager.instance.flush + # See http://blog.humlab.umu.se/samuel/archives/000107.html # for the backgrounding code if $daemonize @@ -421,8 +423,11 @@ class Bot # File.umask 0000 # Ensure sensible umask. Adjust as needed. end - # setup logger based on bot configuration - LoggerManager.instance.set_level(@config['log.level']) + # setup logger based on bot configuration, if not set from the command line + loglevel_set = $opts.has_key?('debug') or $opts.has_key?('loglevel') + LoggerManager.instance.set_level(@config['log.level']) unless loglevel_set + + # Set the logfile LoggerManager.instance.set_logfile(@logfile, @config['log.keep'], @config['log.max_size']) if $daemonize diff --git a/lib/rbot/logger.rb b/lib/rbot/logger.rb index b5f615d7..fd6d485f 100644 --- a/lib/rbot/logger.rb +++ b/lib/rbot/logger.rb @@ -23,13 +23,16 @@ class Bot @file_logger = nil @queue = Queue.new - @thread = start_thread + start_thread end def set_logfile(filename, keep, max_size) @file_logger = Logger.new(filename, keep, max_size*1024*1024) @file_logger.datetime_format = @dateformat @file_logger.level = @logger.level + # make sure the thread is running, which might be false after a fork + # (conveniently, we call set_logfile right after the fork) + start_thread end def set_level(level) @@ -90,10 +93,17 @@ class Bot end end + def flush + while @queue.size > 0 + next + end + end + private def start_thread - Thread.new do + return if @thread and @thread.alive? + @thread = Thread.new do lines = nil while lines = @queue.pop lines.each { |line| |