diff options
| author | Ben Beltran <ben@freshout.us> | 2014-01-15 12:04:20 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@freshout.us> | 2014-01-15 12:04:20 -0600 |
| commit | f6cd3c16e9c98f18c877c66a927bb39cf968b4db (patch) | |
| tree | 132eb6910e815cfaff693614ff9bdacb91f2b55f | |
| parent | 9a8b488630f8ab958efd9c16d8b56d0ca7dc12ae (diff) | |
Normalizes buildLog and adds extendLog
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.
| -rw-r--r-- | lib/cobalt.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/cobalt.js b/lib/cobalt.js index f949b6a..f3effcd 100644 --- a/lib/cobalt.js +++ b/lib/cobalt.js @@ -93,24 +93,39 @@ 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 { |