]>
git.r.bdr.sh - rbdr/cologne/blob - test/cologne.js
f5a6c6e813875b467156632b35f064e8cfeade51
3 let tap
= require('tap');
5 let Cologne
= require('../lib/cologne');
14 for (logObject
of arguments
) {
15 this.values
.push(logObject
);
21 let dummyLoggerA
, dummyLoggerB
, dummyLoggerC
,
22 co
, params
, builtLog
, meta
,
23 valueCheck
, levelCheck
;
27 dummyLoggerA
= Object
.assign({}, dummyLogger
);
28 dummyLoggerB
= Object
.assign({}, dummyLogger
);
29 dummyLoggerC
= Object
.assign({}, dummyLogger
);
42 params
= ['example1', null, undefined, 1, {example: true}];
47 co
.log
.apply(co
, params
);
50 valueCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
51 if (typeof current
._cologneLog
=== 'string') {
56 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
57 if (current
._level
=== 6) {
63 // Now check the values
65 tap
.equal(dummyLoggerA
.values
.length
, params
.length
,
66 '#log() should send every argument to the loggers');
68 tap
.similar(dummyLoggerA
.values
, dummyLoggerB
.values
,
69 '#log() should send the same arguments to all the loggers');
71 tap
.equal(valueCheck
, params
.length
,
72 '#log() should send all objects in cologne log format');
74 tap
.equal(levelCheck
, params
.length
,
75 '#log() should default to level 6');
80 co
.debug
.apply(co
, params
);
81 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
82 if (current
._level
=== 7) {
88 tap
.equal(levelCheck
, params
.length
,
89 '#debug() should set to level 7');
94 co
.info
.apply(co
, params
);
95 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
96 if (current
._level
=== 6) {
102 tap
.equal(levelCheck
, params
.length
,
103 '#info() should set to level 6');
108 co
.notice
.apply(co
, params
);
109 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
110 if (current
._level
=== 5) {
116 tap
.equal(levelCheck
, params
.length
,
117 '#notice() should set to level 5');
122 co
.warn
.apply(co
, params
);
123 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
124 if (current
._level
=== 4) {
130 tap
.equal(levelCheck
, params
.length
,
131 '#warn() should set to level 4');
136 co
.error
.apply(co
, params
);
137 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
138 if (current
._level
=== 3) {
144 tap
.equal(levelCheck
, params
.length
,
145 '#error() should set to level 3');
150 builtLog
= co
.buildLog('example');
152 // With the default level
153 tap
.equal(typeof builtLog
._cologneLog
, 'string',
154 '#buildLog() should return a cologne log');
155 tap
.equal(builtLog
._level
, 6,
156 '#buildLog() should default to level 6');
158 // Now with a specific value
159 builtLog
= co
.buildLog('example', 1);
161 tap
.equal(builtLog
._level
, 1,
162 '#buildLog() should use the specified level');
165 builtLog
= co
.buildLog('example', 1, meta
);
167 tap
.equal(builtLog
.rainbows
, true,
168 '#buildLog() should extend the object with meta if available');
171 * TEST: #log() with builtLog.
175 levelCheck
= dummyLoggerA
.values
.reduce(function (previous
, current
) {
176 if (current
._level
=== 1) {
182 tap
.equal(levelCheck
, 1,
183 '#log() calls using a pre-built cologne log should maintain the log level');
187 * TEST: #removeLogger()
189 co
.removeLogger(dummyLoggerC
);
191 tap
.equal(co
.loggers
.length
, 2,
192 '#removeLogger() should do nothing if it can\'t find a logger');
194 co
.log
.apply(co
, params
);
195 co
.removeLogger(dummyLoggerB
);
198 tap
.equal(co
.loggers
.length
, 1,
199 '#removeLogger() should remove a logger');
201 tap
.notEqual(dummyLoggerB
.values
.length
, dummyLoggerA
.values
.length
,
202 '#removeLogger() should no longer affect removed logs');
208 co
.addLogger(dummyLoggerC
);
209 co
.log
.apply(co
, params
);
211 tap
.equal(dummyLoggerC
.values
.length
, params
.length
,
212 '#addLogger() should add loggers after instance is live');