summaryrefslogtreecommitdiff
path: root/lib/rbot/ircbot.rb
diff options
context:
space:
mode:
authorMatthias Hecker <apoc@geekosphere.org>2015-06-13 17:46:52 +0200
committerMatthias Hecker <apoc@geekosphere.org>2015-06-13 17:46:52 +0200
commit1c761db92a830601c2d46c5a7a53f27dbe70c31a (patch)
treec8f7dd6d411fa8fb9b0abb29d9d11d9f48085ce2 /lib/rbot/ircbot.rb
parent545f21791ad804a52f6b7470403a1fa5a3976f5f (diff)
logging: proper stderr logger for error/fatal
Diffstat (limited to 'lib/rbot/ircbot.rb')
-rw-r--r--lib/rbot/ircbot.rb17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index ab4c2cf1..b972e4e2 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -7,6 +7,7 @@
require 'thread'
require 'etc'
+require 'date'
require 'fileutils'
require 'logger'
@@ -18,6 +19,7 @@ $logger = Logger.new($stderr)
$logger.datetime_format = $dateformat
$logger.level = $cl_loglevel if defined? $cl_loglevel
$logger.level = 0 if $debug
+$logger_stderr = $logger
$log_queue = Queue.new
$log_thread = nil
@@ -56,19 +58,16 @@ def rawlog(level, message=nil, who_pos=1)
# messages originating at the same time, we blank #{who} after the first message
# is output.
# Also, we output strings as-is but for other objects we use pretty_inspect
- case message
- when String
- str = message
- else
- str = message.pretty_inspect rescue '?'
- end
+ message = message.kind_of?(String) ? message : (message.pretty_inspect rescue '?')
qmsg = Array.new
- str.each_line { |l|
+ message.each_line { |l|
qmsg.push [level, l.chomp, who]
who = ' ' * who.size
}
- if level == Logger::Severity::ERROR or level == Logger::Severity::FATAL and not $daemonize
- $stderr.puts str
+ if level >= Logger::Severity::ERROR and not $daemonize
+ qmsg.each do |l|
+ $logger_stderr.add(*l)
+ end
end
$log_queue.push qmsg
end