// 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
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",
if (typeof item !== "object") {
item = {message : item.toString() };
} else {
- item.message = JSON.stringify(item);
+ item.message = Cobalt.stringify(item);
}
item._cobaltLog = true;
global.Formatter = Cobalt.Formatter;
global.Logger = Cobalt.Logger;
global.Console = Cobalt.Console;
+ global.now = Cobalt.now;
+ global.stringify = Cobalt.stringify;
} else {
global.Cobalt = Cobalt;
}