]> git.r.bdr.sh - rbdr/cologne/blob - lib/formatters/token.js
Cobalt 2.0 -> Now with neon 2.0
[rbdr/cologne] / lib / formatters / token.js
1 Module(Cobalt.Formatter, 'Token')({
2 formatString : "{{message}}",
3 replaceRule : /{{(.*?)}}/g,
4 separatorLength : 60,
5 separatorType : "-",
6 format : function (logObject, opts){
7 var indent, indentSize,
8 separatorLength, separatorType,
9 output;
10 indentSize = logObject._indentLevel || 0;
11
12 indent = Array(indentSize + 1).join(' ');
13
14 if (logObject._separator) {
15 separatorLength = logObject._separatorLength || this.separatorLength;
16 separatorType = logObject._separatorType || this.separatorType;
17 output = indent + Array(separatorLength - indentSize + 1).join(separatorType);
18 } else {
19 output = indent + this.parseFormatString(logObject, opts.formatString);
20 }
21
22 if (opts.ansiColor) {
23 output = this.colorize(logObject._level, output);
24 }
25
26 return output;
27 },
28
29 parseFormatString : function (logObject, formatString) {
30 var resultString = '';
31 if (typeof formatString === 'undefined') {
32 formatString = this.formatString;
33 }
34
35 resultString = formatString.replace(this.replaceRule, function(match, paren){
36 return logObject[paren] || "-";
37 });
38
39 return resultString;
40 },
41
42 colorize : function (level, message) {
43 switch(level) {
44 case 0:
45 case 1:
46 case 2:
47 case 3:
48 return message.red;
49 case 4:
50 return message.yellow;
51 case 5:
52 case 6:
53 return message.blue;
54 default:
55 return message;
56 }
57 }
58 });