2017-10-10 13:01:43 +00:00
|
|
|
/**
|
|
|
|
* 控制台输出类
|
|
|
|
*/
|
|
|
|
/*global base*/
|
2019-02-26 09:40:00 +00:00
|
|
|
(function(global) {
|
2017-10-24 10:41:57 +00:00
|
|
|
var Arrays = Java.type('java.util.Arrays');
|
2017-10-17 02:53:51 +00:00
|
|
|
var Level = Java.type('java.util.logging.Level');
|
2018-01-03 14:00:29 +00:00
|
|
|
global.ConsoleDefault = function ConsoleDefault(name) {
|
|
|
|
Object.defineProperty(this, 'name', {
|
2019-02-26 09:40:00 +00:00
|
|
|
get: function() {
|
2018-01-03 14:00:29 +00:00
|
|
|
return this._name;
|
|
|
|
}.bind(this),
|
2019-02-26 09:40:00 +00:00
|
|
|
set: function(name) {
|
2018-01-03 14:00:29 +00:00
|
|
|
this._name = name ? '[' + name + '] ' : '';
|
2018-05-17 10:30:40 +00:00
|
|
|
// noinspection JSUnusedGlobalSymbols
|
2018-01-03 14:00:29 +00:00
|
|
|
this.prefix = name ? '§6[§cMS§6][§b' + name + '§6]§r ' : '§6[§bMiaoScript§6]§r ';
|
|
|
|
}.bind(this)
|
|
|
|
});
|
|
|
|
this.name = name;
|
2019-02-26 09:40:00 +00:00
|
|
|
this.log = this.info = function() {
|
2018-01-03 14:00:29 +00:00
|
|
|
log.info(this.name + Array.prototype.join.call(arguments, ' '));
|
|
|
|
};
|
2018-05-17 10:30:40 +00:00
|
|
|
// noinspection JSUnusedGlobalSymbols
|
2019-02-26 09:40:00 +00:00
|
|
|
this.warn = function() {
|
2018-01-03 14:00:29 +00:00
|
|
|
log.warning(this.name + Array.prototype.join.call(arguments, ' '));
|
|
|
|
};
|
2019-02-26 09:40:00 +00:00
|
|
|
this.error = function() {
|
2018-01-03 14:00:29 +00:00
|
|
|
log.log(Level.SEVERE, this.name + Array.prototype.join.call(arguments, ' '));
|
|
|
|
};
|
2019-02-26 09:40:00 +00:00
|
|
|
this.debug = function() {
|
2018-01-03 14:00:29 +00:00
|
|
|
log.info(this.name + '[DEBUG] ' + Array.prototype.join.call(arguments, ' '));
|
|
|
|
};
|
|
|
|
this.debug = global.debug ? this.debug : global.noop;
|
|
|
|
this.sender = this.info;
|
|
|
|
this.console = this.info;
|
2019-02-26 09:40:00 +00:00
|
|
|
this.object = function(obj) {
|
2018-01-03 14:00:29 +00:00
|
|
|
for (var i in obj) {
|
|
|
|
this.log(i, '=>', obj[i])
|
2017-11-30 05:24:00 +00:00
|
|
|
}
|
2018-05-17 10:30:40 +00:00
|
|
|
};
|
2019-03-13 09:27:17 +00:00
|
|
|
this.ex = function(ex) {
|
2019-03-01 16:29:46 +00:00
|
|
|
this.stack(ex).forEach(function(line) {
|
|
|
|
this.console(line)
|
2019-03-09 02:28:14 +00:00
|
|
|
}.bind(this))
|
2019-03-01 16:29:46 +00:00
|
|
|
};
|
|
|
|
this.stack = function(ex) {
|
2019-03-13 09:27:17 +00:00
|
|
|
// var exType = toString.call(ex)
|
|
|
|
// if (exType !== "[object Error]") {
|
|
|
|
// console.console('§6[WARN] Unknown Type', exType, ex)
|
|
|
|
// ex.printStackTrace();
|
|
|
|
// return []
|
|
|
|
// }
|
|
|
|
var stack = ex.getStackTrace();
|
2019-03-01 16:29:46 +00:00
|
|
|
var cache = ['§4' + ex];
|
2019-03-13 09:27:17 +00:00
|
|
|
if (stack.class) {
|
|
|
|
stack = Arrays.asList(stack)
|
2018-01-03 14:00:29 +00:00
|
|
|
}
|
2019-03-13 09:27:17 +00:00
|
|
|
stack.forEach(function(trace) {
|
|
|
|
if (trace.className.startsWith('<')) {
|
|
|
|
var fileName = trace.fileName
|
2019-03-01 16:29:46 +00:00
|
|
|
fileName = fileName.indexOf('runtime') > -1 ? fileName.split('runtime')[1] : fileName;
|
2019-03-13 09:27:17 +00:00
|
|
|
cache.push(' §e->§c %s => §4%s:%s'.format(fileName, trace.methodName, trace.lineNumber))
|
2018-01-03 14:00:29 +00:00
|
|
|
} else {// %s.%s(§4%s:%s§c)
|
2019-03-13 09:27:17 +00:00
|
|
|
var className = trace.className
|
2019-02-26 09:40:00 +00:00
|
|
|
className = className.startsWith('jdk.nashorn.internal.scripts') ? className.substr(className.lastIndexOf('$') + 1) : className
|
2019-03-13 09:27:17 +00:00
|
|
|
cache.push(' §e->§c %s.%s(§4%s:%s§c)'.format(className, trace.methodName, trace.fileName, trace.lineNumber));
|
2017-10-26 13:01:24 +00:00
|
|
|
}
|
2019-03-01 16:29:46 +00:00
|
|
|
});
|
|
|
|
return cache;
|
|
|
|
}
|
2018-05-17 10:30:40 +00:00
|
|
|
};
|
2018-01-03 14:00:29 +00:00
|
|
|
global.Console = ConsoleDefault;
|
2017-10-26 13:01:24 +00:00
|
|
|
})(global);
|