]> git.r.bdr.sh - rbdr/cologne/blobdiff - lib/cobalt.js
keep on bumping versions because I forget stuff
[rbdr/cologne] / lib / cobalt.js
index 5ae39f2577490fcfd41cfdb2e5c7299b4e6e23da..fa4f6234e350378cb29e397ce324513b847163eb 100644 (file)
@@ -19,8 +19,6 @@
   // Load up loggers + formatters
   if (typeof require === 'function') {
     // Formatters
-    Cobalt.Formatter.Simple = require('./formatters/simple.js').Simple;
-    Cobalt.Formatter.Ansi = require('./formatters/ansi.js').Ansi;
     Cobalt.Formatter.Token = require('./formatters/token.js').Token;
 
     // Loggers
@@ -29,7 +27,7 @@
   }
 
   Cobalt.now = function () {
-    if (typeof performance !== 'undefined') {
+    if (typeof performance !== 'undefined' && performance.timing) {
       return performance.timing.navigationStart + performance.now();
     }
 
     return Date.now();
   }
 
+  // Stringify with circular dereference.
+  Cobalt.stringify = function (object) {
+    var cache = [], stringified;
+    stringified = JSON.stringify(object, function (key, value) {
+      if (typeof value === 'object' && value !== null) {
+        if (cache.indexOf(value) !== -1) {
+          return "[Circular]";
+        }
+        cache.push(value);
+      }
+      return value;
+    });
+    cache = null;
+
+    return stringified;
+  }
+
   Cobalt.Console = Class(Cobalt, 'Console')({
     prototype : {
       from : "Generic Cobalt Logger",
 
       // Builds a Cobalt Log Object
       buildLog : function (item, level) {
-        var co = this, oldItem;
+        var co = this, oldItem, logObject = {};
+
+        if (typeof item === "undefined" || item === null || !item._cobaltLog) {
+          logObject.message = item;
+          logObject._cobaltLog = true;
+          logObject._from = co.from;
+          logObject._level = level || 6;
+          logObject._levelString = co._levelString(logObject._level);
+          logObject._version = co.version;
+          logObject._timestamp = co.now();
+          logObject._indentLevel = co.currentIndent;
+          logObject._color = co.currentColor;
+          logObject._separator = false;
+          return logObject;
+        }
 
-        if (!item._cobaltLog) {
-          if (typeof item !== "object") {
-            item = {message : item.toString() };
-          } else {
-            item.message = JSON.stringify(item);
-          }
+        return item;
+      },
 
-          item._cobaltLog = true;
-          item._from = co.from;
-          item._level = item._level || level || 7;
-          item._levelString = co._levelString(item._level);
-          item._version = co.version;
-          item._timestamp = co.now();
-          item._indentLevel = co.currentIndent;
-          item._color = co.currentColor;
+      extendLog : function (extendingObject) {
+        var co = this, logObject,
+            property;
+
+        logObject = co.buildLog(undefined, 6);
+        extendingObject = extendingObject || {};
+
+        for (property in extendingObject) {
+          if (extendingObject.hasOwnProperty(property)) {
+            logObject[property] = extendingObject[property];
+          }
         }
 
-        return item;
+        return logObject;
       },
 
       buildSeparator : function (type) {
       },
 
       log : function () {
-        this._log.apply(this, [7].concat([].splice.call(arguments, 0)));
+        this._log.apply(this, [6].concat(Array.prototype.slice.call(arguments)));
+      },
+
+      debug : function () {
+        this._log.apply(this, [7].concat(Array.prototype.slice.call(arguments)));
       },
 
       info : function () {
-        this._log.apply(this, [6].concat([].splice.call(arguments, 0)));
+        this._log.apply(this, [6].concat(Array.prototype.slice.call(arguments)));
       },
 
       notice : function () {
-        this._log.apply(this, [5].concat([].splice.call(arguments, 0)));
+        this._log.apply(this, [5].concat(Array.prototype.slice.call(arguments)));
       },
 
       warn : function () {
-        this._log.apply(this, [4].concat([].splice.call(arguments, 0)));
+        this._log.apply(this, [4].concat(Array.prototype.slice.call(arguments)));
       },
 
       error : function () {
-        this._log.apply(this, [3].concat([].splice.call(arguments, 0)));
+        this._log.apply(this, [3].concat(Array.prototype.slice.call(arguments)));
+      },
+
+      dir : function () {
+      },
+
+      time : function () {
+      },
+
+      timeEnd : function () {
+      },
+
+      groupCollapsed : function () {
+      },
+
+      groupEnd : function () {
       },
 
       separator : function (type) {
 
       // Returns the current time in microseconds.
       now : function () {
-        if (typeof performance !== 'undefined') {
+        if (typeof performance !== 'undefined' && performance.timing) {
           return performance.timing.navigationStart + performance.now();
         }
 
     global.Formatter = Cobalt.Formatter;
     global.Logger = Cobalt.Logger;
     global.Console = Cobalt.Console;
+    global.now = Cobalt.now;
+    global.stringify = Cobalt.stringify;
   } else {
     global.Cobalt = Cobalt;
   }