aboutsummaryrefslogtreecommitdiff
path: root/lib/formatters
diff options
context:
space:
mode:
authorBen Beltran <ben@freshout.us>2013-04-03 16:49:03 -0600
committerBen Beltran <ben@freshout.us>2013-04-03 16:49:03 -0600
commitb69497efe78c60742e0bb7ab5fed2b94ce89682e (patch)
treebeec3569a761e90d6f3335d4e656ddb6c16fb291 /lib/formatters
parent03501041337c5234dc12e4a84ddf063142a7857e (diff)
I don't know how git works (massive commit)
Diffstat (limited to 'lib/formatters')
-rw-r--r--lib/formatters/ansi.js47
-rw-r--r--lib/formatters/simple.js30
-rw-r--r--lib/formatters/token.js79
3 files changed, 156 insertions, 0 deletions
diff --git a/lib/formatters/ansi.js b/lib/formatters/ansi.js
new file mode 100644
index 0000000..25ad256
--- /dev/null
+++ b/lib/formatters/ansi.js
@@ -0,0 +1,47 @@
+(function (global) {
+ var Module;
+
+ // Load up dependencies
+ if (typeof require === 'function') {
+ require('colors');
+ var Ne = require('neon');
+ Module = Ne.Module;
+ } else {
+ Module = global.Module;
+ }
+
+ var Cobalt = {};
+ Module(Cobalt, 'Formatter')({});
+
+ Cobalt.Formatter.Ansi = Module(Cobalt.Formatter, 'Ansi')({
+ format : function (logObject, opts){
+ var indent,
+ message;
+
+ indent = Array(logObject._indentLevel + 1).join(' ');
+
+ message = indent + logObject.message;
+
+ switch(logObject._level) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ return message.red;
+ case 4:
+ return message.yellow;
+ case 5:
+ case 6:
+ return message.blue;
+ default:
+ return message;
+ }
+ }
+ });
+
+ if (typeof require === 'function') {
+ global.Ansi = Cobalt.Formatter.Ansi;
+ } else {
+ global.Cobalt.Formatter.Ansi = Cobalt.Formatter.Ansi;
+ }
+}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));
diff --git a/lib/formatters/simple.js b/lib/formatters/simple.js
new file mode 100644
index 0000000..24f65b3
--- /dev/null
+++ b/lib/formatters/simple.js
@@ -0,0 +1,30 @@
+(function (global) {
+ var Module;
+
+ // Load up dependencies
+ if (typeof require === 'function') {
+ var Ne = require('neon');
+ Module = Ne.Module;
+ } else {
+ Module = global.Module;
+ }
+
+ var Cobalt = {};
+ Module(Cobalt, 'Formatter')({});
+
+ Cobalt.Formatter.Simple = Module(Cobalt.Formatter, 'Simple')({
+ format : function (logObject, opts){
+ var indent;
+
+ indent = Array(logObject._indentLevel + 1).join(' ');
+
+ return indent + logObject.message;
+ }
+ });
+
+ if (typeof require === 'function') {
+ global.Simple = Cobalt.Formatter.Simple;
+ } else {
+ global.Cobalt.Formatter.Simple = Cobalt.Formatter.Simple;
+ }
+}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));
diff --git a/lib/formatters/token.js b/lib/formatters/token.js
new file mode 100644
index 0000000..40d4f59
--- /dev/null
+++ b/lib/formatters/token.js
@@ -0,0 +1,79 @@
+(function (global) {
+ var Module;
+
+ // Load up dependencies
+ if (typeof require === 'function') {
+ var Ne = require('neon');
+ Module = Ne.Module;
+ } else {
+ Module = global.Module;
+ }
+
+ var Cobalt = {};
+ Module(Cobalt, 'Formatter')({});
+
+ Cobalt.Formatter.Token = Module(Cobalt.Formatter, 'Token')({
+ formatString : "{{message}}",
+ replaceRule : /{{(.*?)}}/g,
+ separatorLength : 60,
+ separatorType : "-",
+ format : function (logObject, opts){
+ var indent, indentSize,
+ separatorLength, separatorType,
+ output;
+ indentSize = logObject._indentLevel || 0;
+
+ indent = Array(indentSize + 1).join(' ');
+
+ if (logObject._separator) {
+ separatorLength = logObject._separatorLength || this.separatorLength;
+ separatorType = logObject._separatorType || this.separatorType;
+ output = indent + Array(separatorLength - indentSize + 1).join(separatorType);
+ } else {
+ output = indent + this.parseFormatString(logObject, opts.formatString);
+ }
+
+ if (opts.ansiColor) {
+ output = this.colorize(logObject._level, output);
+ }
+
+ return output;
+ },
+
+ parseFormatString : function (logObject, formatString) {
+ var resultString = '';
+ if (typeof formatString === 'undefined') {
+ formatString = this.formatString;
+ }
+
+ resultString = formatString.replace(this.replaceRule, function(match, paren){
+ return logObject[paren] || "-";
+ });
+
+ return resultString;
+ },
+
+ colorize : function (level, message) {
+ switch(level) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ return message.red;
+ case 4:
+ return message.yellow;
+ case 5:
+ case 6:
+ return message.blue;
+ default:
+ return message;
+ }
+ }
+ });
+
+ if (typeof require === 'function') {
+ global.Token = Cobalt.Formatter.Token;
+ } else {
+ global.Cobalt.Formatter.Token = Cobalt.Formatter.Token;
+ }
+}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));