aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Beltran <ben@freshout.us>2013-04-24 12:05:14 -0500
committerBen Beltran <ben@freshout.us>2013-04-24 12:05:14 -0500
commit25d73f5e66b2e4e830491396d44d5fd756a29b8d (patch)
tree5f6184f2da02676ab785df87987a57e036f9494b /lib
parentbc06e8bf44c6d412403af5d9e298e4f91cb1e3fc (diff)
Add Cobalt now/stringify + remove old formatters
Diffstat (limited to 'lib')
-rw-r--r--lib/cobalt.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/cobalt.js b/lib/cobalt.js
index 5ae39f2..9554a04 100644
--- a/lib/cobalt.js
+++ b/lib/cobalt.js
@@ -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
@@ -40,6 +38,23 @@
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",
@@ -82,7 +97,7 @@
if (typeof item !== "object") {
item = {message : item.toString() };
} else {
- item.message = JSON.stringify(item);
+ item.message = Cobalt.stringify(item);
}
item._cobaltLog = true;
@@ -274,6 +289,8 @@
global.Formatter = Cobalt.Formatter;
global.Logger = Cobalt.Logger;
global.Console = Cobalt.Console;
+ global.now = Cobalt.now;
+ global.stringify = Cobalt.stringify;
} else {
global.Cobalt = Cobalt;
}