]> git.r.bdr.sh - rbdr/cologne/blame - lib/formatters/token.js
Adds the file logger
[rbdr/cologne] / lib / formatters / token.js
CommitLineData
db6bc3cb
BB
1Module(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 }
bdedb5e5 21
db6bc3cb
BB
22 if (opts.ansiColor) {
23 output = this.colorize(logObject._level, output);
24 }
bdedb5e5 25
db6bc3cb
BB
26 return output;
27 },
bdedb5e5 28
db6bc3cb
BB
29 parseFormatString : function (logObject, formatString) {
30 var resultString = '';
31 if (typeof formatString === 'undefined') {
32 formatString = this.formatString;
bdedb5e5 33 }
bdedb5e5 34
db6bc3cb
BB
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 }
bdedb5e5 57 }
db6bc3cb 58});