summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-15 15:01:37 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-15 18:16:44 +0200
commit56eacc7b8dc2a58949ff8211b982493e21f7ab33 (patch)
treec8c95e4bc0dc49998dc4dac2f0d122cc814afb81
parent0ed9bf788d778eba03d65ad19cea6c0a5c432870 (diff)
debug logging: don't raise on SecurityError
Some scripts (from the scripts plugin) can trigger the logging functions (debug, warning, info etc) in a $SAFE context: this causes the logger to fail. Catch SecurityError in raw_log() to prevent these valid scripts from failing.
-rw-r--r--lib/rbot/ircbot.rb41
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 8767531d..cd073b32 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -39,26 +39,29 @@ class Exception
end
def rawlog(level, message=nil, who_pos=1)
- call_stack = caller
- if call_stack.length > who_pos
- who = call_stack[who_pos].sub(%r{(?:.+)/([^/]+):(\d+)(:in .*)?}) { "#{$1}:#{$2}#{$3}" }
- else
- who = "(unknown)"
- end
- # Output each line. To distinguish between separate messages and multi-line
- # 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
+ begin
+ call_stack = caller
+ if call_stack.length > who_pos
+ who = call_stack[who_pos].sub(%r{(?:.+)/([^/]+):(\d+)(:in .*)?}) { "#{$1}:#{$2}#{$3}" }
+ else
+ who = "(unknown)"
+ end
+ # Output each line. To distinguish between separate messages and multi-line
+ # 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
+ end
+ str.each_line { |l|
+ $logger.add(level, l.chomp, who)
+ who.gsub!(/./," ")
+ }
+ rescue SecurityError
end
- str.each_line { |l|
- $logger.add(level, l.chomp, who)
- who.gsub!(/./," ")
- }
end
def log_session_start