fix: 修复Java原生异常打印错误

This commit is contained in:
coding 2017-10-24 10:41:57 +00:00
parent 4cb597e63e
commit 2cab200e41

View File

@ -4,6 +4,7 @@
/*global base*/ /*global base*/
var log = base.getLog().static; var log = base.getLog().static;
(function(global){ (function(global){
var Arrays = Java.type('java.util.Arrays');
var Level = Java.type('java.util.logging.Level'); var Level = Java.type('java.util.logging.Level');
var Console = function (name) { var Console = function (name) {
Object.defineProperty(this, 'name', { Object.defineProperty(this, 'name', {
@ -27,13 +28,25 @@ var log = base.getLog().static;
this.debug = function () { this.debug = function () {
log.d(this.name + Array.prototype.join.call(arguments, ' ')); log.d(this.name + Array.prototype.join.call(arguments, ' '));
} }
this.sender = function () {
var args = Array.prototype.slice.call(arguments, 1);
log.sender();
}
this.ex = function (ex) { this.ex = function (ex) {
log.console('§4' + ex); log.console('§4' + ex);
ex.getStackTrace().forEach(function (stack) { var track = ex.getStackTrace();
log.console(' §e位于 §c%s §4行%s', stack.fileName, stack.lineNumber); if (track.class) { track = Arrays.asList(track) }
if (track.forEach) {
track.forEach(function (stack) {
if (stack.className.startsWith('<')) {
log.console(' §e位于 §c%s => §c%s §4行%s', stack.fileName, stack.methodName, stack.lineNumber);
} else {
log.console(' §e位于 §c%s.%s(§4%s:%s§c)', stack.className, stack.methodName, stack.fileName, stack.lineNumber);
}
}); });
} }
} }
}
global.Console = Console; global.Console = Console;
global.console = new Console(); global.console = new Console();
})(global) })(global)