forked from CloudBotIRC/CloudBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CloudBotIRC#223 from linuxdaemon/gonzobot+hook-errors
Add logging of hook errors to configurable log channel
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import traceback | ||
|
||
from cloudbot import hook | ||
from cloudbot.util import web | ||
|
||
logchannel = "" | ||
|
||
|
||
@hook.post_hook | ||
def on_hook_end(error, message, launched_hook, launched_event): | ||
if error is not None and logchannel: | ||
message("Error occurred in {}.{}".format(launched_hook.plugin.title, launched_hook.function_name), logchannel) | ||
|
||
lines = traceback.format_exception(*error) | ||
last_line = lines[-1] | ||
message(last_line, logchannel) | ||
url = web.paste('\n'.join(lines)) | ||
message("Traceback: " + url, logchannel) | ||
|
||
event_data = launched_event.__dict__.items() | ||
lines = ["{} = {}".format(k, v) for k, v in event_data] | ||
url = web.paste('\n'.join(lines)) | ||
message("Event: " + url, logchannel) |