]>
git.r.bdr.sh - rbdr/cologne/blob - lib/formatters/token.js
f562f1c9fbeceb8beddcef1ec278952f4fff19bd
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 (Cobalt
.Formatter
.Token
.__objectSpy
) {
75 Cobalt
.Formatter
.Token
.__objectSpy
.destroy();
78 if (typeof require
=== 'function') {
79 global
.Token
= Cobalt
.Formatter
.Token
;
81 global
.Cobalt
.Formatter
.Token
= Cobalt
.Formatter
.Token
;
83 }(typeof window
!== 'undefined' ? window : (typeof exports
!== 'undefined' ? exports : self
)));