]>
git.r.bdr.sh - rbdr/cologne/blob - lib/formatters/token.js
40d4f599d1a64d6b4863fabdcc5bdfe6b0365c70
4 // Load up dependencies
5 if (typeof require
=== 'function') {
6 var Ne
= require('neon');
9 Module
= global
.Module
;
13 Module(Cobalt
, 'Formatter')({});
15 Cobalt
.Formatter
.Token
= Module(Cobalt
.Formatter
, 'Token')({
16 formatString : "{{message}}",
17 replaceRule : /{{(.*?)}}/g,
20 format : function (logObject
, opts
){
21 var indent
, indentSize
,
22 separatorLength
, separatorType
,
24 indentSize
= logObject
._indentLevel
|| 0;
26 indent
= Array(indentSize
+ 1).join(' ');
28 if (logObject
._separator
) {
29 separatorLength
= logObject
._separatorLength
|| this.separatorLength
;
30 separatorType
= logObject
._separatorType
|| this.separatorType
;
31 output
= indent
+ Array(separatorLength
- indentSize
+ 1).join(separatorType
);
33 output
= indent
+ this.parseFormatString(logObject
, opts
.formatString
);
37 output
= this.colorize(logObject
._level
, output
);
43 parseFormatString : function (logObject
, formatString
) {
44 var resultString
= '';
45 if (typeof formatString
=== 'undefined') {
46 formatString
= this.formatString
;
49 resultString
= formatString
.replace(this.replaceRule
, function(match
, paren
){
50 return logObject
[paren
] || "-";
56 colorize : function (level
, message
) {
64 return message
.yellow
;
74 if (typeof require
=== 'function') {
75 global
.Token
= Cobalt
.Formatter
.Token
;
77 global
.Cobalt
.Formatter
.Token
= Cobalt
.Formatter
.Token
;
79 }(typeof window
!== 'undefined' ? window : (typeof exports
!== 'undefined' ? exports : self
)));