]> git.r.bdr.sh - rbdr/cologne/commitdiff
Normalizes buildLog and adds extendLog
authorBen Beltran <redacted>
Wed, 15 Jan 2014 18:04:20 +0000 (12:04 -0600)
committerBen Beltran <redacted>
Wed, 15 Jan 2014 18:04:20 +0000 (12:04 -0600)
buildLog now generates default messages as INFO instead of DEBUG.
Similarly, now includes the _separator flag as false for consistnecy.
It also properly handles undefined and null.
Finally, it creates extendLog which extends a dummy objectLog with the
passed object.

lib/cobalt.js

index f949b6a925f8aa9ad5a069c6b0b66b65155ca59b..f3effcdcd76b4953b19e6247a85bdd702f20be83 100644 (file)
       buildLog : function (item, level) {
         var co = this, oldItem, logObject = {};
 
-        item = item || {};
-
-        if (!item._cobaltLog) {
+        if (typeof item === "undefined" || item === null || !item._cobaltLog) {
           logObject.message = item;
           logObject._cobaltLog = true;
           logObject._from = co.from;
-          logObject._level = item._level || level || 7;
-          logObject._levelString = co._levelString(item._level);
+          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;
         }
 
         return item;
       },
 
+      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 logObject;
+      },
+
       buildSeparator : function (type) {
         var co = this;
         return {