diff options
| author | Ben Beltran <ben@nsovocal.com> | 2015-01-09 10:23:41 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2015-01-09 10:23:41 -0600 |
| commit | 6c37857f165d160ede4bf1a1b02b1204655633f3 (patch) | |
| tree | 014df31264c5d750459ab2459d1ace0695b28e6d /lib/formatters | |
| parent | 2957910b21de88334c1ee56c44c90a876f2dbb69 (diff) | |
Makes formatter truly extensible, adds isoDate opt
Diffstat (limited to 'lib/formatters')
| -rw-r--r-- | lib/formatters/token.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/formatters/token.js b/lib/formatters/token.js index 4fa7d57..f3afba2 100644 --- a/lib/formatters/token.js +++ b/lib/formatters/token.js @@ -2,13 +2,23 @@ Module(Cobalt.Formatter, 'Token')({ formatString : "{{message}}", replaceRule : /{{(.*?)}}/g, separatorLength : 60, + isoDate : true, separatorType : "-", format : function (logObject, opts){ var indent, indentSize, separatorLength, separatorType, - output; + output, property; indentSize = logObject._indentLevel || 0; + // Extend opts + if (opts) { + for (property in opts) { + if (opts.hasOwnProperty(property)) { + this[property] = opts[property]; + } + } + } + indent = Array(indentSize + 1).join(' '); if (logObject._separator) { @@ -16,10 +26,10 @@ Module(Cobalt.Formatter, 'Token')({ separatorType = logObject._separatorType || this.separatorType; output = indent + Array(separatorLength - indentSize + 1).join(separatorType); } else { - output = indent + this.parseFormatString(logObject, opts.formatString); + output = indent + this.parseFormatString(logObject, this.formatString); } - if (opts.ansiColor) { + if (this.ansiColor) { output = this.colorize(logObject._level, output); } @@ -33,8 +43,13 @@ Module(Cobalt.Formatter, 'Token')({ } resultString = formatString.replace(this.replaceRule, function(match, paren){ + var date; + if (paren === "_timestamp" && this.isoDate) { + date = new Date(logObject[paren]); + return date.toISOString(); + } return logObject[paren] || "-"; - }); + }.bind(this)); return resultString; }, |