Skip to content
Browse files

Improve logging of plugins and common plugin errors

  • Loading branch information...
1 parent 4f4ddb3 commit ac03a9bd34918f68acebcbde98c5f4dfee9bdb2a @smfreegard smfreegard committed Jan 12, 2012
Showing with 32 additions and 7 deletions.
  1. +11 −0 constants.js
  2. +21 −7 plugins.js
View
11 constants.js
@@ -19,3 +19,14 @@ exports.import = function (object) {
}
}
}
+
+exports.translate = function (value) {
+ var t = {};
+ for (var k in exports) {
+ if (typeof exports[k] === 'number') {
+ t[exports[k]] = k.toUpperCase();
+ }
+ }
+ if (t[value]) return t[value];
+ return 'UNKNOWN';
+}
View
28 plugins.js
@@ -198,19 +198,33 @@ plugins.run_next_hook = function(hook, object, params) {
if (called_once) {
if (hook != 'log')
- object.logerror("callback called multiple times. Ignoring subsequent calls");
+ object.logerror(item[0].name + ' plugin ran callback multiple times - ignoring subsequent calls');
+ // Write a stack trace to the log to aid debugging
+ object.logerror((new Error).stack);
return;
}
called_once++;
if (!retval) retval = constants.cont;
+ // Log what is being run
+ if (item && hook !== 'log') {
+ var log = 'logdebug';
+ if (utils.in_array(retval, [constants.deny, constants.denysoft, constants.denydisconnect, constants.denysoftdisconnect])) {
+ log = 'loginfo';
+ }
+ object[log]([
+ 'hook=' + hook,
+ 'plugin=' + item[0].name,
+ 'function=' + item[1],
+ 'params="' + ((params) ? ((typeof params === 'string') ? params : params[0]) : '') + '"',
+ 'retval=' + constants.translate(retval),
+ 'msg="' + ((msg) ? msg : '') + '"',
+ ].join(' '));
+ }
if (object.hooks_to_run.length == 0 ||
retval !== constants.cont)
{
var respond_method = hook + "_respond";
- if (item && utils.in_array(retval, [constants.deny, constants.denysoft, constants.denydisconnect])) {
- if (hook != 'log') {
- object.loginfo("plugin returned deny(soft?): ", msg);
- }
+ if (item && utils.in_array(retval, [constants.deny, constants.denysoft, constants.denydisconnect, constants.denysoftdisconnect])) {
object.deny_respond = function (deny_retval, deny_msg) {
switch(deny_retval) {
case constants.ok:
@@ -253,8 +267,8 @@ plugins.run_next_hook = function(hook, object, params) {
if (item[0].timeout && hook != 'log') {
timeout_id = setTimeout(function () {
object.logcrit("Plugin " + item[0].name +
- " timed out - make sure it calls the callback");
- callback(constants.denysoft, "timeout");
+ " timed out on hook " + hook + " - make sure it calls the callback");
+ callback(constants.denysoft, "plugin timeout");
}, item[0].timeout * 1000);
}

0 comments on commit ac03a9b

Please sign in to comment.
Something went wrong with that request. Please try again.