diff --git a/libs/console.js b/libs/console.js index 118eb86d..9054100b 100644 --- a/libs/console.js +++ b/libs/console.js @@ -45,19 +45,31 @@ } this.levelName = levelName; - this.ctx = $ ? $.ctx : null; + this.ctx = typeof $ !== "undefined" && $ ? $.ctx : null; this.logLevel = LOG_LEVELS[levelName]; this.args = args; this.time = performance.now() - startTime; } + function padRight(str, c, n) { + var length = str.length; + if (!c || length >= n) { + return str; + } + var max = (n - length) / c.length; + for (var i = 0; i < max; i++) { + str += c; + } + return str; + } + LogItem.prototype = { get messagePrefix() { - var s = J2ME.Context.currentContextPrefix(); + var s = typeof J2ME !== "undefined" ? J2ME.Context.currentContextPrefix() : ""; if (false) { s = this.time.toFixed(2) + " " + s; } - return s.toString().padRight(" ", 4) + " | "; + return padRight(s.toString(), " ", 4) + " | "; }, get message() {