]>
git.r.bdr.sh - rbdr/cologne/blob - test/cologne/logger/console.js
ffc1876249923d53c63a3ca520d11ecb5f698c1b
3 let tap
= require('tap');
5 let ConsoleLogger
= require('../../../lib/cologne/logger/console');
8 let dummyFormatter
, dummyConsole
, logObjectA
, logObjectB
, regularLogger
,
9 overrideLogger
, formattedLogger
, params
;
13 format: function (logObject
) {
14 this.values
.push(logObject
);
21 _log: function (type
, args
) {
22 this.values
[type
] = args
;
25 this._log('log', Array
.prototype.splice
.call(arguments
, [0]));
28 this._log('warn', Array
.prototype.splice
.call(arguments
, [0]));
31 this._log('error', Array
.prototype.splice
.call(arguments
, [0]));
34 this._log('info', Array
.prototype.splice
.call(arguments
, [0]));
39 _timestamp: Date
.now() + .134,
41 _from: 'Dummy Logger',
48 _timestamp: Date
.now() + .134,
50 _from: 'Dummy Logger',
56 params
= [logObjectA
, logObjectB
];
58 regularLogger
= new ConsoleLogger({});
59 overrideLogger
= new ConsoleLogger({
62 formattedLogger
= new ConsoleLogger({
63 console: dummyConsole
,
64 formatter: dummyFormatter
68 * TEST: #log() - regular
71 tap
.equal(regularLogger
.console
, global
.console
,
72 'It should default to the global console');
75 * TEST: #log() - override
78 logObjectA
._level
= 5;
79 logObjectB
._level
= 6;
80 overrideLogger
.log
.apply(overrideLogger
, params
); // should go to info
82 logObjectA
._level
= 4;
83 logObjectB
._level
= 4;
84 overrideLogger
.log
.apply(overrideLogger
, params
); // should go to warn
86 logObjectA
._level
= 1;
87 logObjectB
._level
= 3;
88 overrideLogger
.log
.apply(overrideLogger
, params
); // should go to error
90 logObjectA
._level
= 7;
91 logObjectB
._level
= 7;
92 overrideLogger
.log
.apply(overrideLogger
, params
); // should go to log
94 tap
.equal(dummyConsole
.values
.log
.length
, params
.length
,
95 'It should send debug messages to console\'s #log');
96 tap
.equal(dummyConsole
.values
.info
.length
, params
.length
,
97 'It should send info and notice messages to console\'s #info');
98 tap
.equal(dummyConsole
.values
.warn
.length
, params
.length
,
99 'It should send warn messages to console\'s #warn');
100 tap
.equal(dummyConsole
.values
.error
.length
, params
.length
,
101 'It should send error messages to console\'s #error');
104 * TEST: #log() - with formatter
107 formattedLogger
.log
.apply(formattedLogger
, params
); // should go to log
109 tap
.similar(dummyFormatter
.values
, params
,
110 'If available, it should send the objects to the formatter');