]>
git.r.bdr.sh - rbdr/cologne/blob - lib/formatters/token.js
1 Module(Cobalt
.Formatter
, 'Token')({
2 formatString : "{{message}}",
3 replaceRule : /{{(.*?)}}/g,
7 format : function (logObject
, opts
){
8 var indent
, indentSize
,
9 separatorLength
, separatorType
,
11 indentSize
= logObject
._indentLevel
|| 0;
15 for (property
in opts
) {
16 if (opts
.hasOwnProperty(property
)) {
17 this[property
] = opts
[property
];
22 indent
= Array(indentSize
+ 1).join(' ');
24 if (logObject
._separator
) {
25 separatorLength
= logObject
._separatorLength
|| this.separatorLength
;
26 separatorType
= logObject
._separatorType
|| this.separatorType
;
27 output
= indent
+ Array(separatorLength
- indentSize
+ 1).join(separatorType
);
29 output
= indent
+ this.parseFormatString(logObject
, this.formatString
);
33 output
= this.colorize(logObject
._level
, output
);
39 parseFormatString : function (logObject
, formatString
) {
40 var resultString
= '';
41 if (typeof formatString
=== 'undefined') {
42 formatString
= this.formatString
;
45 resultString
= formatString
.replace(this.replaceRule
, function(match
, paren
){
47 if (paren
=== "_timestamp" && this.isoDate
) {
48 date
= new Date(logObject
[paren
]);
49 return date
.toISOString();
51 return logObject
[paren
] || "-";
57 colorize : function (level
, message
) {
65 return message
.yellow
;