X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/ce8edf20a15c643b05c7867c416123c16debd120..7f4b2a023bda5dcf9ea830b95b88bceefb331dbd:/lib/loggers/console.js diff --git a/lib/loggers/console.js b/lib/loggers/console.js index dc077c8..c4031eb 100644 --- a/lib/loggers/console.js +++ b/lib/loggers/console.js @@ -1,91 +1,70 @@ -(function (global) { - var Module, Class; +Class(Cobalt.Logger, 'JsConsole')({ + prototype : { + console : null, + formatterOpts : {}, - // Load up dependencies - if (typeof require === 'function') { - var Ne = require('neon'); - Module = Ne.Module; - Class = Ne.Class; - } else { - Module = global.Module; - Class = global.Class; - } - - var Cobalt = {}; - Module(Cobalt, 'Logger')({}); - - Cobalt.Logger.JsConsole = Class(Cobalt.Logger, 'JsConsole')({ - prototype : { - console : null, - formatterOpts : {}, + init : function (config) { + var logger = this, + property; - init : function (config) { - var logger = this, - property; - - if (config) { - for (property in config) { - logger[property] = config[property]; - } + if (config) { + for (property in config) { + logger[property] = config[property]; } + } - if (!logger.console) { - logger.console = console; - } - }, + if (!logger.console) { + logger.console = console; + } + }, - log : function () { - var i, messageArray = [], message, severity; + log : function () { + var i, message = [], severity; - for (i = 0; i < arguments.length; i++) { - messageArray.push(this.format(arguments[i])); + for (i = 0; i < arguments.length; i++) { + // We're not formatting objects for now. + + if (!arguments[i].__skipConsole && !arguments[i].message.__skipConsole) { + if (typeof arguments[i].message === 'object') { + message.push(arguments[i].message); + } else { + message.push(this.format(arguments[i])); + } if (!severity) { severity = arguments[i]._level } } + } - message = messageArray.join(' '); - - switch (severity){ - case 0: - case 1: - case 2: - case 3: - this.console.error(message); - break; - case 4: - this.console.warn(message); - break; - case 5: - case 6: - this.console.info(message); - break; - case 7: - default: - this.console.log(message); - break; - } - }, - - format : function (logObject) { - // Usually what you want to do here is format. Preferably using - // someone inside Cobalt.Formatter - if (this.formatter) { - return this.formatter.format(logObject, this.formatterOpts); - } - - return logObject; + switch (severity){ + case 0: + case 1: + case 2: + case 3: + this.console.error.apply(this.console, message); + break; + case 4: + this.console.warn.apply(this.console, message); + break; + case 5: + case 6: + this.console.info.apply(this.console, message); + break; + case 7: + default: + this.console.log.apply(this.console, message); + break; } - } - }); + }, - if (Cobalt.Logger.JsConsole.__objectSpy) { - Cobalt.Logger.JsConsole.__objectSpy.destroy(); - } + format : function (logObject) { + // Usually what you want to do here is format. Preferably using + // someone inside Cobalt.Formatter + if (this.formatter) { + return this.formatter.format(logObject, this.formatterOpts); + } - if (typeof require === 'function') { - global.JsConsole = Cobalt.Logger.JsConsole; - } else { - global.Cobalt.Logger.JsConsole = Cobalt.Logger.JsConsole; + return logObject.message; + } } -}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self))); +});