From 46925f9b529c6581a662fb923f5b6d2cfe68c801 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 1 Feb 2020 02:41:00 +0800 Subject: [PATCH] feat: add system level Signed-off-by: MiaoWoo --- src/main/resources/bios.js | 7 +++-- src/main/resources/core/console.js | 46 ++++++++++++++++++------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index 7fadf61..fb9a77c 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -17,9 +17,12 @@ var global = this; global.debug = true; } if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) { - logger.info('Running debugging mode...'); + logger.info('Running in debug mode...'); global.debug = true; - global.trace = true; + } + if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "level"))) { + global.level = base.read(java.nio.file.Paths.get(root, "level")) + logger.info('Set system level to [' + global.level + ']...'); } // Check Class Loader, Sometimes Server will can't find plugin.yml file loader = checkClassLoader(); diff --git a/src/main/resources/core/console.js b/src/main/resources/core/console.js index d41d13b..6fbc862 100644 --- a/src/main/resources/core/console.js +++ b/src/main/resources/core/console.js @@ -1,19 +1,29 @@ -(function(logger) { - function log() { - logger.info(Array.prototype.join.call(arguments, ' ')) - } - function _proxy(prefix) { - return function() { - log('[' + prefix + ']', Array.prototype.join.call(arguments, ' ')) +// @ts-check +( + /** + * @param {{ info: (arg0: string) => void; }} logger + */ + function(logger) { + function log() { + logger.info(Array.prototype.join.call(arguments, ' ')) } - } - return { - log: log, - info: log, - ex: log, - trace: global.trace ? _proxy('TRACE') : global.noop, - debug: global.debug ? _proxy('DEBUG') : global.noop, - warn: _proxy('WARN'), - error: _proxy('ERROR') - }; -}) + /** + * @param {string} prefix + */ + function _proxy(prefix) { + return function() { + log('[' + prefix + ']', Array.prototype.join.call(arguments, ' ')) + } + } + return { + log: log, + info: log, + ex: log, + // @ts-ignore + trace: global.level === "trace" ? _proxy('TRACE') : global.noop, + // @ts-ignore + debug: global.debug ? _proxy('DEBUG') : global.noop, + warn: _proxy('WARN'), + error: _proxy('ERROR') + }; + })