diff options
Diffstat (limited to 'js/src/Ice/Logger.js')
-rw-r--r-- | js/src/Ice/Logger.js | 154 |
1 files changed, 75 insertions, 79 deletions
diff --git a/js/src/Ice/Logger.js b/js/src/Ice/Logger.js index 38ab8d8ee4b..cafcff58753 100644 --- a/js/src/Ice/Logger.js +++ b/js/src/Ice/Logger.js @@ -6,88 +6,84 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** - -(function(global){ - var Ice = global.Ice || {}; - require("Ice/Class"); +var Ice = require("../Ice/Class").Ice; - var Logger = Ice.Class({ - __init__: function(prefix) - { - if(prefix !== undefined && prefix.length > 0) - { - this._prefix = prefix + ": "; - } - else - { - this._prefix = ""; - } - }, - print: function(message) - { - this.write(message, false); - }, - trace: function(category, message) - { - var s = []; - var d = new Date(); - s.push("-- "); - s.push(this.timestamp()); - s.push(' '); - s.push(this._prefix); - s.push(category); - s.push(": "); - s.push(message); - this.write(s.join(""), true); - }, - warning: function(message) - { - var s = []; - var d = new Date(); - s.push("-! "); - s.push(this.timestamp()); - s.push(' '); - s.push(this._prefix); - s.push("warning: "); - s.push(message); - this.write(s.join(""), true); - }, - error: function(message) +var Logger = Ice.Class({ + __init__: function(prefix) + { + if(prefix !== undefined && prefix.length > 0) { - var s = []; - var d = new Date(); - s.push("!! "); - s.push(this.timestamp()); - s.push(' '); - s.push(this._prefix); - s.push("error: "); - s.push(message); - this.write(s.join(""), true); - }, - cloneWithPrefix: function(prefix) - { - return new Logger(prefix); - }, - write: function(message, indent) + this._prefix = prefix + ": "; + } + else { - if(indent) - { - message = message.replace(/\n/g, "\n "); - } - - console.log(message); - }, - timestamp: function() + this._prefix = ""; + } + }, + print: function(message) + { + this.write(message, false); + }, + trace: function(category, message) + { + var s = []; + var d = new Date(); + s.push("-- "); + s.push(this.timestamp()); + s.push(' '); + s.push(this._prefix); + s.push(category); + s.push(": "); + s.push(message); + this.write(s.join(""), true); + }, + warning: function(message) + { + var s = []; + var d = new Date(); + s.push("-! "); + s.push(this.timestamp()); + s.push(' '); + s.push(this._prefix); + s.push("warning: "); + s.push(message); + this.write(s.join(""), true); + }, + error: function(message) + { + var s = []; + var d = new Date(); + s.push("!! "); + s.push(this.timestamp()); + s.push(' '); + s.push(this._prefix); + s.push("error: "); + s.push(message); + this.write(s.join(""), true); + }, + cloneWithPrefix: function(prefix) + { + return new Logger(prefix); + }, + write: function(message, indent) + { + if(indent) { - var d = new Date(); - var mon = d.getMonth() + 1; - mon = mon < 10 ? "0" + mon : mon; - var day = d.getDate(); - day = day < 10 ? "0" + day : day; - return mon + "-" + day + "-" + d.getFullYear() + " " + d.toLocaleTimeString() + "." + d.getMilliseconds(); + message = message.replace(/\n/g, "\n "); } - }); - Ice.Logger = Logger; - global.Ice = Ice; -}(typeof (global) === "undefined" ? window : global)); + + console.log(message); + }, + timestamp: function() + { + var d = new Date(); + var mon = d.getMonth() + 1; + mon = mon < 10 ? "0" + mon : mon; + var day = d.getDate(); + day = day < 10 ? "0" + day : day; + return mon + "-" + day + "-" + d.getFullYear() + " " + d.toLocaleTimeString() + "." + d.getMilliseconds(); + } +}); +Ice.Logger = Logger; +module.exports.Ice = Ice; |