summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-26 22:48:47 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-26 22:48:47 +0000
commit9223bcdf64dbcea6eaa7ae352ce5b9a12ff18003 (patch)
tree7e1cb267f685f52c1e3a1738141a5f1ef4453496 /lib
parent82af99ab6793dc6fc976fa97f9ff3d12b73688ba (diff)
Logging now also logs the filename and function it's being called from
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/ircbot.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 7f258b0b..7de676b5 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -5,15 +5,27 @@ require 'fileutils'
$debug = false unless $debug
$daemonize = false unless $daemonize
+# TODO we should use the actual Logger class
def rawlog(code="", message=nil)
if !code || code.empty?
c = " "
else
c = code.to_s[0,1].upcase + ":"
end
+ call_stack = caller
+ case call_stack.length
+ when 0
+ $stderr.puts "ERROR IN THE LOGGING SYSTEM, THIS CAN'T HAPPEN"
+ who = "WTF1?? "
+ when 1
+ $stderr.puts "ERROR IN THE LOGGING SYSTEM, THIS CAN'T HAPPEN"
+ who = "WTF2?? "
+ else
+ who = call_stack[1].match(%r{(?:.+)/([^/]+):(\d+)(?::(in .*))?})[1,3].join(":")
+ end
stamp = Time.now.strftime("%Y/%m/%d %H:%M:%S")
message.to_s.each_line { |l|
- $stdout.puts "#{c} [#{stamp}] #{l}"
+ $stdout.puts "#{c} [#{stamp}] #{who} -- #{l}"
}
$stdout.flush
end
@@ -23,7 +35,7 @@ def log(message=nil)
end
def log_session_end
- log("\n=== #{botclass} session ended ===") if $daemonize
+ rawlog("", "\n=== #{botclass} session ended ===") if $daemonize
end
def debug(message=nil)