From a94d31b65f7e4134217b9623aab992287c480011 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 27 Jul 2006 10:05:52 +0000 Subject: New logging systems now works correctly even when the bot is daemonized --- lib/rbot/ircbot.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 8030fd41..d435ac4c 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -35,23 +35,23 @@ def log_session_end end def debug(message=nil, who_pos=1) - rawlog(Logger::Severity::DEBUG, message) + rawlog(Logger::Severity::DEBUG, message, who_pos) end def log(message=nil, who_pos=1) - rawlog(Logger::Severity::INFO, message) + rawlog(Logger::Severity::INFO, message, who_pos) end def warning(message=nil, who_pos=1) - rawlog(Logger::Severity::WARN, message) + rawlog(Logger::Severity::WARN, message, who_pos) end def error(message=nil, who_pos=1) - rawlog(Logger::Severity::ERROR, message) + rawlog(Logger::Severity::ERROR, message, who_pos) end def fatal(message=nil, who_pos=1) - rawlog(Logger::Severity::FATAL, message) + rawlog(Logger::Severity::FATAL, message, who_pos) end debug "debug test" @@ -282,8 +282,18 @@ class IrcBot # On Windows, there's not such thing as /dev/null STDIN.reopen "NUL" end - STDOUT.reopen @logfile, "a" - STDERR.reopen @logfile, "a" + def STDOUT.write(str=nil) + log str, 2 + return str.to_s.length + end + def STDERR.write(str=nil) + if str.to_s.match(/:\d+: warning:/) + warning str, 2 + else + error str, 2 + end + return str.to_s.length + end end # Set the new logfile and loglevel. This must be done after the daemonizing -- cgit v1.2.3