X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/b69497efe78c60742e0bb7ab5fed2b94ce89682e..f77b762e787faebdc553ef608888411781976b29:/lib/cobalt.js?ds=inline diff --git a/lib/cobalt.js b/lib/cobalt.js index 45f0e26..5ae39f2 100644 --- a/lib/cobalt.js +++ b/lib/cobalt.js @@ -6,6 +6,7 @@ var Ne = require('neon'); Module = Ne.Module; Class = Ne.Class; + var Microtime = require('microtime'); } else { Module = global.Module; Class = global.Class; @@ -27,6 +28,18 @@ Cobalt.Logger.Socket = require('./loggers/socket.js').Socket; } + Cobalt.now = function () { + if (typeof performance !== 'undefined') { + return performance.timing.navigationStart + performance.now(); + } + + if (typeof Microtime !== 'undefined') { + return Microtime.nowDouble() * 1000; + } + + return Date.now(); + } + Cobalt.Console = Class(Cobalt, 'Console')({ prototype : { from : "Generic Cobalt Logger", @@ -63,13 +76,16 @@ // Builds a Cobalt Log Object buildLog : function (item, level) { - var co = this; + var co = this, oldItem; if (!item._cobaltLog) { if (typeof item !== "object") { - item = { _cobaltLog : true, message : item.toString() }; + item = {message : item.toString() }; + } else { + item.message = JSON.stringify(item); } + item._cobaltLog = true; item._from = co.from; item._level = item._level || level || 7; item._levelString = co._levelString(item._level); @@ -90,22 +106,28 @@ _version : co.version, _timestamp : co.now(), _separatorType : type, - _indentLevel : co.currentIndent + _indentLevel : co.currentIndent, + _color : co.currentColor } }, _log : function (severity) { var co = this, logString, + logObjectArray = [], i, j; for (i = 1; i < arguments.length; i++) { - logObject = co.buildLog(arguments[i], severity); - - for (j = 0; j < co.loggers.length; j++) { - co.loggers[j].log(logObject); + if (typeof arguments[i] === 'undefined') { + logObjectArray.push(co.buildLog("undefined", severity)); + } else { + logObjectArray.push(co.buildLog(arguments[i], severity)); } } + + for (j = 0; j < co.loggers.length; j++) { + co.loggers[j].log.apply(co.loggers[j], logObjectArray); + } }, log : function () { @@ -206,8 +228,8 @@ return performance.timing.navigationStart + performance.now(); } - if (typeof process !== 'undefined') { - return process.hrtime(); + if (typeof Microtime !== 'undefined') { + return Microtime.nowDouble() * 1000; } return Date.now(); @@ -244,6 +266,10 @@ } }); + if (Cobalt.Console.__objectSpy) { + Cobalt.Console.__objectSpy.destroy(); + } + if (typeof require === 'function') { global.Formatter = Cobalt.Formatter; global.Logger = Cobalt.Logger;