- Cobalt.Console = Class(Cobalt, 'Console')({
- prototype : {
- from : "Generic Cobalt Logger",
- version : "0.1.0",
- currentIndent : 0,
- indentSize : 2,
- loggers : [],
- separatorLength : 120,
- currentColor : "black",
-
- // Initialize instance of cobalt console
- // and extend configuration.
- init : function (config) {
- var co = this,
- property;
-
- if (config) {
- for (property in config) {
- co[property] = config[property];
- }
- }
- },
-
- addLogger : function (logger) {
- this.loggers.push(logger);
- },
-
- removeLogger : function (logger) {
- var index;
-
- index = this.loggers.indexOf(logger);
- this.loggers.splice(index, 1);
- },
-
- // Builds a Cobalt Log Object
- buildLog : function (item, level) {
- var co = this;
-
- if (!item._cobaltLog) {
- if (typeof item !== "object") {
- item = { _cobaltLog : true, message : item.toString() };
- }
-
- 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;
+ 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;
+}
+
+Class(Cobalt, 'Console')({
+ prototype : {
+ from : "Generic Cobalt Logger",
+ version : "0.1.0",
+ currentIndent : 0,
+ indentSize : 2,
+ loggers : [],
+ separatorLength : 120,
+ currentColor : "black",
+
+ // Initialize instance of cobalt console
+ // and extend configuration.
+ init : function (config) {
+ var co = this,
+ property;
+
+ if (config) {
+ for (property in config) {
+ co[property] = config[property];