From bba65fdfcae07e2399e1770b03538c47f097d8fd Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Tue, 23 Dec 2014 14:31:20 +0000 Subject: [PATCH] Fixes issue #179 --- docs/API-Reference.md | 3 ++- src/main/js/lib/console.js | 3 ++- src/main/js/lib/plugin.js | 5 +++-- src/main/js/lib/scriptcraft.js | 17 +++++++++++------ src/main/resources/boot.js | 5 +++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/docs/API-Reference.md b/docs/API-Reference.md index 34c6967..f4fcc3f 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -1042,7 +1042,7 @@ The ScriptCraft console methods work like the [Web API implementation][webcons]. console.log('Hello %s', 'world'); Basic variable substitution is supported (ScriptCraft's implementation -of console uses the Bukkit Plugin [Logger][lgr] under the hood and +of console uses the Bukkit Plugin [Logger][lgr] or Canary Plugin [Logman][cmlgr] under the hood and uses [java.lang.String.format()][strfmt] for variable substitution. All output will be sent to the server console (not in-game). @@ -1057,6 +1057,7 @@ ScriptCraft uses Java's [String.format()][strfmt] so any string substitution ide } [lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html +[cmlgr]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/logger/Logman.html [strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...) [webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console diff --git a/src/main/js/lib/console.js b/src/main/js/lib/console.js index 2e64c94..854aa34 100644 --- a/src/main/js/lib/console.js +++ b/src/main/js/lib/console.js @@ -16,7 +16,7 @@ The ScriptCraft console methods work like the [Web API implementation][webcons]. console.log('Hello %s', 'world'); Basic variable substitution is supported (ScriptCraft's implementation -of console uses the Bukkit Plugin [Logger][lgr] under the hood and +of console uses the Bukkit Plugin [Logger][lgr] or Canary Plugin [Logman][cmlgr] under the hood and uses [java.lang.String.format()][strfmt] for variable substitution. All output will be sent to the server console (not in-game). @@ -31,6 +31,7 @@ ScriptCraft uses Java's [String.format()][strfmt] so any string substitution ide } [lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html +[cmlgr]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/logger/Logman.html [strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...) [webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console diff --git a/src/main/js/lib/plugin.js b/src/main/js/lib/plugin.js index aa5983c..af792cf 100644 --- a/src/main/js/lib/plugin.js +++ b/src/main/js/lib/plugin.js @@ -1,5 +1,5 @@ 'use strict'; - +/*global persist,exports,config,__plugin,require*/ var File = java.io.File, FileWriter = java.io.FileWriter, PrintWriter = java.io.PrintWriter; @@ -84,7 +84,8 @@ exports.autoload = function( context, pluginDir, logger, options ) { } } catch ( e ) { if ( typeof logger != 'undefined' ) { - logger.error( 'Plugin ' + pluginPath + ' ' + e ); + var msg = 'Plugin ' + pluginPath + ' ' + e ; + __plugin.canary ? logger.error( msg ) : logger.severe( msg ); } else { java.lang.System.out.println( 'Error: Plugin ' + pluginPath + ' ' + e ); } diff --git a/src/main/js/lib/scriptcraft.js b/src/main/js/lib/scriptcraft.js index a2a7057..73ee136 100644 --- a/src/main/js/lib/scriptcraft.js +++ b/src/main/js/lib/scriptcraft.js @@ -454,7 +454,7 @@ function __onEnable ( __engine, __plugin, __script ) { } result = JSON.parse(contents); } catch ( e ) { - logger.error( 'Error evaluating ' + canonizedFilename + ', ' + e ); + logError('Error evaluating ' + canonizedFilename + ', ' + e ); } finally { try { @@ -497,7 +497,7 @@ function __onEnable ( __engine, __plugin, __script ) { result = __engine.eval( wrappedCode ); // issue #103 avoid side-effects of || operator on Mac Rhino } catch ( e ) { - logger.error( 'Error evaluating ' + canonizedFilename + ', ' + e ); + logError('Error evaluating ' + canonizedFilename + ', ' + e ); } finally { try { @@ -508,7 +508,7 @@ function __onEnable ( __engine, __plugin, __script ) { } } else { if ( warnOnFileNotFound ) { - logger.warning( canonizedFilename + ' not found' ); + logWarn(canonizedFilename + ' not found' ); } } return result; @@ -612,12 +612,12 @@ function __onEnable ( __engine, __plugin, __script ) { echo(sender, JSON.stringify( jsResult, replacer, 2) ); } } catch ( displayError ) { - logger.error( 'Error while trying to display result: ' + jsResult + ', Error: '+ displayError ); + logError('Error while trying to display result: ' + jsResult + ', Error: '+ displayError) ; } } } } catch ( e ) { - logger.error( 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e ); + logError( 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e ); echo( sender, 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e ); throw e; } finally { @@ -650,7 +650,12 @@ function __onEnable ( __engine, __plugin, __script ) { server = Bukkit.server; logger = __plugin.logger; } - + function logError(msg){ + __plugin.canary ? logger.error( msg ) : logger.severe( msg ); + } + function logWarn(msg){ + __plugin.canary ? logger.warn( msg ) : logger.warning( msg ); + } var File = java.io.File, FileReader = java.io.FileReader, BufferedReader = java.io.BufferedReader, diff --git a/src/main/resources/boot.js b/src/main/resources/boot.js index 3816c2b..d0f4d54 100644 --- a/src/main/resources/boot.js +++ b/src/main/resources/boot.js @@ -59,7 +59,7 @@ var __scboot = null; */ __scboot = function ( plugin, engine, classLoader ) { - var logger = plugin.logman, + var logger = plugin.canary ? plugin.logman : plugin.logger, initScriptFile = new File(jsPlugins,initScript), zips = ['lib','plugins','modules'], i = 0, @@ -90,7 +90,8 @@ var __scboot = null; engine.eval(new FileReader(initScriptFile)); __onEnable(engine, plugin, initScriptFile); }catch ( e ){ - logger.error('Error evaluating ' + initScriptFile + ': ' + e); + var msg = 'Error evaluating ' + initScriptFile + ': ' + e; + plugin.canary ? logger.error(msg) : logger.severe(msg); throw e; } };