@villedemontreal/logger 6.5.2 → 6.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/configs.d.ts +16 -0
- package/dist/config/configs.js +15 -0
- package/dist/config/configs.js.map +1 -0
- package/dist/scripts/index.d.ts +6 -0
- package/dist/scripts/index.js +35 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/lint.d.ts +6 -0
- package/dist/scripts/lint.js +31 -0
- package/dist/scripts/lint.js.map +1 -0
- package/dist/scripts/lintFix.d.ts +6 -0
- package/dist/scripts/lintFix.js +40 -0
- package/dist/scripts/lintFix.js.map +1 -0
- package/dist/scripts/scripts-tests/testingGlobalOptions.d.ts +4 -0
- package/dist/scripts/scripts-tests/testingGlobalOptions.js +3 -0
- package/dist/scripts/scripts-tests/testingGlobalOptions.js.map +1 -0
- package/dist/scripts/scripts-tests/testingScript1.d.ts +7 -0
- package/dist/scripts/scripts-tests/testingScript1.js +40 -0
- package/dist/scripts/scripts-tests/testingScript1.js.map +1 -0
- package/dist/scripts/scripts-tests/testingScript2.d.ts +7 -0
- package/dist/scripts/scripts-tests/testingScript2.js +28 -0
- package/dist/scripts/scripts-tests/testingScript2.js.map +1 -0
- package/dist/scripts/tests/index.d.ts +3 -0
- package/dist/scripts/tests/index.js +10 -0
- package/dist/scripts/tests/index.js.map +1 -0
- package/dist/scripts/tests/showCoverage.d.ts +13 -0
- package/dist/scripts/tests/showCoverage.js +55 -0
- package/dist/scripts/tests/showCoverage.js.map +1 -0
- package/dist/scripts/tests/test.d.ts +13 -0
- package/dist/scripts/tests/test.js +42 -0
- package/dist/scripts/tests/test.js.map +1 -0
- package/dist/scripts/tests/testUnits.d.ts +15 -0
- package/dist/scripts/tests/testUnits.js +109 -0
- package/dist/scripts/tests/testUnits.js.map +1 -0
- package/dist/src/config/configs.js.map +1 -1
- package/dist/src/config/constants.d.ts +1 -1
- package/dist/src/config/constants.js +3 -3
- package/dist/src/config/constants.js.map +1 -1
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/logger.js +32 -25
- package/dist/src/logger.js.map +1 -1
- package/dist/src/logger.test.js +134 -123
- package/dist/src/logger.test.js.map +1 -1
- package/package.json +21 -17
- package/src/config/configs.ts +7 -7
- package/src/config/constants.ts +4 -4
- package/src/logger.test.ts +30 -30
- package/src/logger.ts +18 -16
package/dist/src/logger.test.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.timeout = void 0;
|
|
4
13
|
const general_utils_1 = require("@villedemontreal/general-utils");
|
|
@@ -29,7 +38,7 @@ describe('Logger tests', () => {
|
|
|
29
38
|
let logger;
|
|
30
39
|
const stdoutWriteBackup = process.stdout.write;
|
|
31
40
|
let output;
|
|
32
|
-
before(
|
|
41
|
+
before(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
42
|
// ==========================================
|
|
34
43
|
// Tweaks the configs for this tests file.
|
|
35
44
|
// ==========================================
|
|
@@ -40,9 +49,9 @@ describe('Logger tests', () => {
|
|
|
40
49
|
// ==========================================
|
|
41
50
|
// Creates the logger
|
|
42
51
|
// ==========================================
|
|
43
|
-
logger_1.initLogger(loggerConfig, 'default', true);
|
|
52
|
+
(0, logger_1.initLogger)(loggerConfig, 'default', true);
|
|
44
53
|
logger = new logger_1.Logger('test');
|
|
45
|
-
});
|
|
54
|
+
}));
|
|
46
55
|
let expectTwoCalls = false;
|
|
47
56
|
let keepSecondCallOnly = false;
|
|
48
57
|
let firstCallDone = false;
|
|
@@ -54,29 +63,29 @@ describe('Logger tests', () => {
|
|
|
54
63
|
// A stadard "function" is required here, because
|
|
55
64
|
// of the use of "arguments".
|
|
56
65
|
// tslint:disable-next-line:only-arrow-functions
|
|
57
|
-
process.stdout.write = function () {
|
|
66
|
+
process.stdout.write = function (...args) {
|
|
58
67
|
if (!expectTwoCalls) {
|
|
59
|
-
output +=
|
|
68
|
+
output += args[0];
|
|
60
69
|
process.stdout.write = stdoutWriteBackup;
|
|
61
70
|
return;
|
|
62
71
|
}
|
|
63
72
|
if (!firstCallDone) {
|
|
64
73
|
if (!keepSecondCallOnly) {
|
|
65
|
-
output +=
|
|
74
|
+
output += args[0];
|
|
66
75
|
}
|
|
67
76
|
firstCallDone = true;
|
|
68
77
|
}
|
|
69
78
|
else {
|
|
70
|
-
output +=
|
|
79
|
+
output += args[0];
|
|
71
80
|
process.stdout.write = stdoutWriteBackup;
|
|
72
81
|
}
|
|
73
82
|
};
|
|
74
83
|
chai_1.assert.isTrue(general_utils_1.utils.isBlank(output));
|
|
75
84
|
}
|
|
76
|
-
beforeEach(
|
|
85
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
86
|
restartCustomWriter();
|
|
78
|
-
});
|
|
79
|
-
it('string message',
|
|
87
|
+
}));
|
|
88
|
+
it('string message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
89
|
logger.error('allo');
|
|
81
90
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
82
91
|
const jsonObj = JSON.parse(output);
|
|
@@ -88,8 +97,8 @@ describe('Logger tests', () => {
|
|
|
88
97
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
89
98
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
90
99
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
91
|
-
});
|
|
92
|
-
it('string message and extra text message',
|
|
100
|
+
}));
|
|
101
|
+
it('string message and extra text message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
102
|
logger.error('allo', 'salut');
|
|
94
103
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
95
104
|
const jsonObj = JSON.parse(output);
|
|
@@ -100,15 +109,15 @@ describe('Logger tests', () => {
|
|
|
100
109
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
101
110
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
102
111
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
103
|
-
});
|
|
104
|
-
it('custom object message',
|
|
112
|
+
}));
|
|
113
|
+
it('custom object message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
114
|
logger.error({
|
|
106
115
|
key1: {
|
|
107
116
|
key3: 'val3',
|
|
108
|
-
key4: 'val4'
|
|
117
|
+
key4: 'val4',
|
|
109
118
|
},
|
|
110
119
|
key2: 'val2',
|
|
111
|
-
msg: 'blabla'
|
|
120
|
+
msg: 'blabla',
|
|
112
121
|
});
|
|
113
122
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
114
123
|
const jsonObj = JSON.parse(output);
|
|
@@ -116,22 +125,22 @@ describe('Logger tests', () => {
|
|
|
116
125
|
chai_1.assert.strictEqual(jsonObj.msg, 'blabla');
|
|
117
126
|
chai_1.assert.deepEqual(jsonObj.key1, {
|
|
118
127
|
key3: 'val3',
|
|
119
|
-
key4: 'val4'
|
|
128
|
+
key4: 'val4',
|
|
120
129
|
});
|
|
121
130
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
122
131
|
chai_1.assert.isNotNull(jsonObj.src.file);
|
|
123
132
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
124
133
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
125
134
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
126
|
-
});
|
|
127
|
-
it('custom object message and extra text message',
|
|
135
|
+
}));
|
|
136
|
+
it('custom object message and extra text message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
137
|
logger.error({
|
|
129
138
|
key1: {
|
|
130
139
|
key3: 'val3',
|
|
131
|
-
key4: 'val4'
|
|
140
|
+
key4: 'val4',
|
|
132
141
|
},
|
|
133
142
|
key2: 'val2',
|
|
134
|
-
msg: 'blabla'
|
|
143
|
+
msg: 'blabla',
|
|
135
144
|
}, 'my text message');
|
|
136
145
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
137
146
|
const jsonObj = JSON.parse(output);
|
|
@@ -139,15 +148,15 @@ describe('Logger tests', () => {
|
|
|
139
148
|
chai_1.assert.strictEqual(jsonObj.msg, 'blabla - my text message');
|
|
140
149
|
chai_1.assert.deepEqual(jsonObj.key1, {
|
|
141
150
|
key3: 'val3',
|
|
142
|
-
key4: 'val4'
|
|
151
|
+
key4: 'val4',
|
|
143
152
|
});
|
|
144
153
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
145
154
|
chai_1.assert.isNotNull(jsonObj.src.file);
|
|
146
155
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
147
156
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
148
157
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
149
|
-
});
|
|
150
|
-
it('regular Error object and extra text message',
|
|
158
|
+
}));
|
|
159
|
+
it('regular Error object and extra text message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
160
|
logger.error(new Error('my error message'), 'my text message');
|
|
152
161
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
153
162
|
const jsonObj = JSON.parse(output);
|
|
@@ -159,8 +168,8 @@ describe('Logger tests', () => {
|
|
|
159
168
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
160
169
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
161
170
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
162
|
-
});
|
|
163
|
-
it('null Error object and extra text message',
|
|
171
|
+
}));
|
|
172
|
+
it('null Error object and extra text message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
173
|
logger.error(null, 'my text message');
|
|
165
174
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
166
175
|
const jsonObj = JSON.parse(output);
|
|
@@ -171,8 +180,8 @@ describe('Logger tests', () => {
|
|
|
171
180
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
172
181
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
173
182
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
174
|
-
});
|
|
175
|
-
it('undefined Error object and extra text message',
|
|
183
|
+
}));
|
|
184
|
+
it('undefined Error object and extra text message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
185
|
logger.error(undefined, 'my text message');
|
|
177
186
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
178
187
|
const jsonObj = JSON.parse(output);
|
|
@@ -183,8 +192,8 @@ describe('Logger tests', () => {
|
|
|
183
192
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
184
193
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
185
194
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
186
|
-
});
|
|
187
|
-
it('array message',
|
|
195
|
+
}));
|
|
196
|
+
it('array message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
197
|
// ==========================================
|
|
189
198
|
// Two calls to "process.stdout.write" will
|
|
190
199
|
// be made because an error for the invalid
|
|
@@ -196,22 +205,22 @@ describe('Logger tests', () => {
|
|
|
196
205
|
'toto',
|
|
197
206
|
{
|
|
198
207
|
key1: 'val1',
|
|
199
|
-
key2: 'val2'
|
|
200
|
-
}
|
|
208
|
+
key2: 'val2',
|
|
209
|
+
},
|
|
201
210
|
]);
|
|
202
211
|
const jsonObj = JSON.parse(output);
|
|
203
212
|
chai_1.assert.deepEqual(jsonObj._arrayMsg, [
|
|
204
213
|
'toto',
|
|
205
214
|
{
|
|
206
215
|
key1: 'val1',
|
|
207
|
-
key2: 'val2'
|
|
208
|
-
}
|
|
216
|
+
key2: 'val2',
|
|
217
|
+
},
|
|
209
218
|
]);
|
|
210
219
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
211
220
|
chai_1.assert.isNotNull(jsonObj.src.file);
|
|
212
221
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
213
|
-
});
|
|
214
|
-
it('array message and extra text message',
|
|
222
|
+
}));
|
|
223
|
+
it('array message and extra text message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
215
224
|
// ==========================================
|
|
216
225
|
// Two calls to "process.stdout.write" will
|
|
217
226
|
// be made because an error for the invalid
|
|
@@ -223,47 +232,47 @@ describe('Logger tests', () => {
|
|
|
223
232
|
'toto',
|
|
224
233
|
{
|
|
225
234
|
key1: 'val1',
|
|
226
|
-
key2: 'val2'
|
|
227
|
-
}
|
|
235
|
+
key2: 'val2',
|
|
236
|
+
},
|
|
228
237
|
], 'my text message');
|
|
229
238
|
const jsonObj = JSON.parse(output);
|
|
230
239
|
chai_1.assert.deepEqual(jsonObj._arrayMsg, [
|
|
231
240
|
'toto',
|
|
232
241
|
{
|
|
233
242
|
key1: 'val1',
|
|
234
|
-
key2: 'val2'
|
|
235
|
-
}
|
|
243
|
+
key2: 'val2',
|
|
244
|
+
},
|
|
236
245
|
]);
|
|
237
246
|
chai_1.assert.strictEqual(jsonObj.msg, 'my text message');
|
|
238
247
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
239
248
|
chai_1.assert.isNotNull(jsonObj.src.file);
|
|
240
249
|
chai_1.assert.isNotNull(jsonObj.src.line);
|
|
241
|
-
});
|
|
242
|
-
it('log level - debug',
|
|
250
|
+
}));
|
|
251
|
+
it('log level - debug', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
252
|
logger.debug('allo');
|
|
244
253
|
chai_1.assert.strictEqual(output, '');
|
|
245
|
-
});
|
|
246
|
-
it('log level - info',
|
|
254
|
+
}));
|
|
255
|
+
it('log level - info', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
247
256
|
logger.info('allo');
|
|
248
257
|
const jsonObj = JSON.parse(output);
|
|
249
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.INFO));
|
|
250
|
-
});
|
|
251
|
-
it('log level - warning',
|
|
258
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.INFO));
|
|
259
|
+
}));
|
|
260
|
+
it('log level - warning', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
261
|
logger.warning('allo');
|
|
253
262
|
const jsonObj = JSON.parse(output);
|
|
254
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.WARNING));
|
|
255
|
-
});
|
|
256
|
-
it('log level - error',
|
|
263
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.WARNING));
|
|
264
|
+
}));
|
|
265
|
+
it('log level - error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
266
|
logger.error('allo');
|
|
258
267
|
const jsonObj = JSON.parse(output);
|
|
259
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.ERROR));
|
|
260
|
-
});
|
|
261
|
-
it('log level - custom valid',
|
|
268
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.ERROR));
|
|
269
|
+
}));
|
|
270
|
+
it('log level - custom valid', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
271
|
logger.log(logger_1.LogLevel.INFO, 'allo');
|
|
263
272
|
const jsonObj = JSON.parse(output);
|
|
264
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.INFO));
|
|
265
|
-
});
|
|
266
|
-
it('log level - custom invalid',
|
|
273
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.INFO));
|
|
274
|
+
}));
|
|
275
|
+
it('log level - custom invalid', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
267
276
|
// ==========================================
|
|
268
277
|
// Two calls to "process.stdout.write" will
|
|
269
278
|
// be made because an error for the invalid
|
|
@@ -273,32 +282,32 @@ describe('Logger tests', () => {
|
|
|
273
282
|
keepSecondCallOnly = true;
|
|
274
283
|
logger.log('nope', 'allo');
|
|
275
284
|
const jsonObj = JSON.parse(output);
|
|
276
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.ERROR));
|
|
285
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.ERROR));
|
|
277
286
|
chai_1.assert.strictEqual(jsonObj.msg, 'allo');
|
|
278
|
-
});
|
|
279
|
-
it('newline after each log - string',
|
|
287
|
+
}));
|
|
288
|
+
it('newline after each log - string', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
280
289
|
expectTwoCalls = true;
|
|
281
290
|
logger.error('111');
|
|
282
291
|
logger.error('222');
|
|
283
292
|
const pos = output.indexOf('\n');
|
|
284
293
|
chai_1.assert.isTrue(pos > -1);
|
|
285
294
|
chai_1.assert.strictEqual(output.charAt(pos + 1), '{');
|
|
286
|
-
});
|
|
287
|
-
it('newline after each log - complexe objects',
|
|
295
|
+
}));
|
|
296
|
+
it('newline after each log - complexe objects', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
297
|
expectTwoCalls = true;
|
|
289
298
|
logger.error({
|
|
290
299
|
key1: 'val1',
|
|
291
|
-
key2: 'val2'
|
|
300
|
+
key2: 'val2',
|
|
292
301
|
});
|
|
293
302
|
logger.error({
|
|
294
303
|
key1: 'val1',
|
|
295
|
-
key2: 'val2'
|
|
304
|
+
key2: 'val2',
|
|
296
305
|
});
|
|
297
306
|
const pos = output.indexOf('\n');
|
|
298
307
|
chai_1.assert.isTrue(pos > -1);
|
|
299
308
|
chai_1.assert.strictEqual(output.charAt(pos + 1), '{');
|
|
300
|
-
});
|
|
301
|
-
it('date message',
|
|
309
|
+
}));
|
|
310
|
+
it('date message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
311
|
const someDate = new Date();
|
|
303
312
|
logger.error(someDate);
|
|
304
313
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
@@ -306,12 +315,12 @@ describe('Logger tests', () => {
|
|
|
306
315
|
chai_1.assert.isTrue(_.isObject(jsonObj));
|
|
307
316
|
chai_1.assert.strictEqual(jsonObj.msg, someDate.toString());
|
|
308
317
|
chai_1.assert.isTrue(_.isDate(someDate));
|
|
309
|
-
});
|
|
318
|
+
}));
|
|
310
319
|
// ==========================================
|
|
311
320
|
// Error controller log messages
|
|
312
321
|
// ==========================================
|
|
313
322
|
describe('Error controller log messages', () => {
|
|
314
|
-
it('app and version properties',
|
|
323
|
+
it('app and version properties', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
315
324
|
const packageJson = require(`${constants_1.constants.libRoot}/package.json`);
|
|
316
325
|
const appName = packageJson.name;
|
|
317
326
|
const appVersion = packageJson.version;
|
|
@@ -322,29 +331,29 @@ describe('Logger tests', () => {
|
|
|
322
331
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.APP_NAME], appName);
|
|
323
332
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.APP_VERSION], appVersion);
|
|
324
333
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.CORRELATION_ID], TESTING_CID);
|
|
325
|
-
});
|
|
334
|
+
}));
|
|
326
335
|
});
|
|
327
336
|
// ==========================================
|
|
328
337
|
// LazyLogger tests
|
|
329
338
|
// ==========================================
|
|
330
339
|
describe('LazyLogger tests', () => {
|
|
331
340
|
let lazyLogger;
|
|
332
|
-
beforeEach(
|
|
341
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
342
|
lazyLogger = new lazyLogger_1.LazyLogger('titi', (name) => {
|
|
334
343
|
const logger2 = new logger_1.Logger('titi');
|
|
335
344
|
return logger2;
|
|
336
345
|
});
|
|
337
|
-
});
|
|
338
|
-
it('debug',
|
|
346
|
+
}));
|
|
347
|
+
it('debug', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
339
348
|
lazyLogger.debug('allo');
|
|
340
349
|
chai_1.assert.isTrue(general_utils_1.utils.isBlank(output));
|
|
341
|
-
});
|
|
342
|
-
it('info',
|
|
350
|
+
}));
|
|
351
|
+
it('info', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
343
352
|
lazyLogger.info('allo');
|
|
344
353
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
345
354
|
const jsonObj = JSON.parse(output);
|
|
346
355
|
chai_1.assert.isTrue(_.isObject(jsonObj));
|
|
347
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.INFO));
|
|
356
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.INFO));
|
|
348
357
|
chai_1.assert.strictEqual(jsonObj.name, 'titi');
|
|
349
358
|
chai_1.assert.strictEqual(jsonObj.msg, 'allo');
|
|
350
359
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
@@ -353,13 +362,13 @@ describe('Logger tests', () => {
|
|
|
353
362
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
354
363
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
355
364
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.CORRELATION_ID], TESTING_CID);
|
|
356
|
-
});
|
|
357
|
-
it('warning',
|
|
365
|
+
}));
|
|
366
|
+
it('warning', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
358
367
|
lazyLogger.warning('allo');
|
|
359
368
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
360
369
|
const jsonObj = JSON.parse(output);
|
|
361
370
|
chai_1.assert.isTrue(_.isObject(jsonObj));
|
|
362
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.WARNING));
|
|
371
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.WARNING));
|
|
363
372
|
chai_1.assert.strictEqual(jsonObj.name, 'titi');
|
|
364
373
|
chai_1.assert.strictEqual(jsonObj.msg, 'allo');
|
|
365
374
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
@@ -368,13 +377,13 @@ describe('Logger tests', () => {
|
|
|
368
377
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
369
378
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
370
379
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.CORRELATION_ID], TESTING_CID);
|
|
371
|
-
});
|
|
372
|
-
it('error',
|
|
380
|
+
}));
|
|
381
|
+
it('error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
373
382
|
lazyLogger.error('allo');
|
|
374
383
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
375
384
|
const jsonObj = JSON.parse(output);
|
|
376
385
|
chai_1.assert.isTrue(_.isObject(jsonObj));
|
|
377
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.ERROR));
|
|
386
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.ERROR));
|
|
378
387
|
chai_1.assert.strictEqual(jsonObj.name, 'titi');
|
|
379
388
|
chai_1.assert.strictEqual(jsonObj.msg, 'allo');
|
|
380
389
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
@@ -383,13 +392,13 @@ describe('Logger tests', () => {
|
|
|
383
392
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
384
393
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
385
394
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.CORRELATION_ID], TESTING_CID);
|
|
386
|
-
});
|
|
387
|
-
it('log',
|
|
395
|
+
}));
|
|
396
|
+
it('log', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
388
397
|
lazyLogger.log(logger_1.LogLevel.INFO, 'allo');
|
|
389
398
|
chai_1.assert.isTrue(!general_utils_1.utils.isBlank(output));
|
|
390
399
|
const jsonObj = JSON.parse(output);
|
|
391
400
|
chai_1.assert.isTrue(_.isObject(jsonObj));
|
|
392
|
-
chai_1.assert.strictEqual(jsonObj.level, logger_1.convertLogLevelToPinoNumberLevel(logger_1.LogLevel.INFO));
|
|
401
|
+
chai_1.assert.strictEqual(jsonObj.level, (0, logger_1.convertLogLevelToPinoNumberLevel)(logger_1.LogLevel.INFO));
|
|
393
402
|
chai_1.assert.strictEqual(jsonObj.name, 'titi');
|
|
394
403
|
chai_1.assert.strictEqual(jsonObj.msg, 'allo');
|
|
395
404
|
chai_1.assert.isNotNull(jsonObj.src);
|
|
@@ -398,8 +407,8 @@ describe('Logger tests', () => {
|
|
|
398
407
|
chai_1.assert.strictEqual(jsonObj.logType, constants_1.constants.logging.logType.MONTREAL);
|
|
399
408
|
chai_1.assert.strictEqual(jsonObj.logTypeVersion, '2');
|
|
400
409
|
chai_1.assert.strictEqual(jsonObj[constants_1.constants.logging.properties.CORRELATION_ID], TESTING_CID);
|
|
401
|
-
});
|
|
402
|
-
it('logger creator is required',
|
|
410
|
+
}));
|
|
411
|
+
it('logger creator is required', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
403
412
|
try {
|
|
404
413
|
const lazyLogger2 = new lazyLogger_1.LazyLogger('titi', null);
|
|
405
414
|
chai_1.assert.fail();
|
|
@@ -416,7 +425,7 @@ describe('Logger tests', () => {
|
|
|
416
425
|
catch (err) {
|
|
417
426
|
/* ok */
|
|
418
427
|
}
|
|
419
|
-
});
|
|
428
|
+
}));
|
|
420
429
|
});
|
|
421
430
|
// ==========================================
|
|
422
431
|
// Global log level
|
|
@@ -424,14 +433,14 @@ describe('Logger tests', () => {
|
|
|
424
433
|
describe('Global log level', () => {
|
|
425
434
|
let childLogger;
|
|
426
435
|
before(() => {
|
|
427
|
-
childLogger = logger_1.createLogger('testing child logger');
|
|
436
|
+
childLogger = (0, logger_1.createLogger)('testing child logger');
|
|
428
437
|
});
|
|
429
438
|
afterEach(() => {
|
|
430
439
|
// Reset the default logging
|
|
431
|
-
logger_1.setGlobalLogLevel(loggerConfig.getLogLevel());
|
|
440
|
+
(0, logger_1.setGlobalLogLevel)(loggerConfig.getLogLevel());
|
|
432
441
|
});
|
|
433
442
|
it('log debug message when global log level set to DEBUG', () => {
|
|
434
|
-
logger_1.setGlobalLogLevel(logger_1.LogLevel.DEBUG);
|
|
443
|
+
(0, logger_1.setGlobalLogLevel)(logger_1.LogLevel.DEBUG);
|
|
435
444
|
logger.debug('this is the debug message');
|
|
436
445
|
let jsonObj = JSON.parse(output);
|
|
437
446
|
chai_1.assert.strictEqual(jsonObj.msg, 'this is the debug message');
|
|
@@ -450,7 +459,7 @@ describe('Logger tests', () => {
|
|
|
450
459
|
});
|
|
451
460
|
it('filter debug message when global log level set to WARNING', () => {
|
|
452
461
|
chai_1.assert.isTrue(general_utils_1.utils.isBlank(output));
|
|
453
|
-
logger_1.setGlobalLogLevel(logger_1.LogLevel.WARNING);
|
|
462
|
+
(0, logger_1.setGlobalLogLevel)(logger_1.LogLevel.WARNING);
|
|
454
463
|
logger.debug('this is my filtered the debug message');
|
|
455
464
|
chai_1.assert.isTrue(general_utils_1.utils.isBlank(output), 'Did not filter debug message as expected.');
|
|
456
465
|
childLogger.debug('this is my filtered the debug message');
|
|
@@ -469,8 +478,8 @@ describe('Logger tests', () => {
|
|
|
469
478
|
});
|
|
470
479
|
it('apply current log level to new created logger - INFO', () => {
|
|
471
480
|
chai_1.assert.isTrue(general_utils_1.utils.isBlank(output));
|
|
472
|
-
logger_1.setGlobalLogLevel(logger_1.LogLevel.WARNING);
|
|
473
|
-
const newLogger = logger_1.createLogger('testing logger');
|
|
481
|
+
(0, logger_1.setGlobalLogLevel)(logger_1.LogLevel.WARNING);
|
|
482
|
+
const newLogger = (0, logger_1.createLogger)('testing logger');
|
|
474
483
|
newLogger.info('this is the info message for newly created logger');
|
|
475
484
|
chai_1.assert.isTrue(general_utils_1.utils.isBlank(output), 'Did not filter info message as expected.');
|
|
476
485
|
newLogger.warning('this is the warning message');
|
|
@@ -485,80 +494,82 @@ describe('Logger tests', () => {
|
|
|
485
494
|
let logger;
|
|
486
495
|
let testingLogDir;
|
|
487
496
|
let testingLogFile;
|
|
488
|
-
before(
|
|
497
|
+
before(() => __awaiter(this, void 0, void 0, function* () {
|
|
489
498
|
testingLogDir = `${constants_1.constants.libRoot}/output/testingLogs`;
|
|
490
499
|
if (general_utils_1.utils.isDir(testingLogDir)) {
|
|
491
|
-
|
|
500
|
+
yield general_utils_1.utils.clearDir(testingLogDir);
|
|
492
501
|
}
|
|
493
502
|
else {
|
|
494
503
|
fs.mkdirsSync(testingLogDir);
|
|
495
504
|
}
|
|
496
505
|
testingLogFile = `${testingLogDir}/application.log`;
|
|
497
|
-
});
|
|
498
|
-
after(
|
|
499
|
-
|
|
500
|
-
});
|
|
501
|
-
beforeEach(
|
|
506
|
+
}));
|
|
507
|
+
after(() => __awaiter(this, void 0, void 0, function* () {
|
|
508
|
+
yield general_utils_1.utils.deleteDir(testingLogDir);
|
|
509
|
+
}));
|
|
510
|
+
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
502
511
|
if (fs.existsSync(testingLogFile)) {
|
|
503
512
|
fs.unlinkSync(testingLogFile);
|
|
504
513
|
}
|
|
505
514
|
chai_1.assert.isFalse(fs.existsSync(testingLogFile));
|
|
506
|
-
});
|
|
515
|
+
}));
|
|
507
516
|
/**
|
|
508
517
|
* Logging with Pino is asynchronous.
|
|
509
518
|
* We need to make sure the log is written to file by waiting.
|
|
510
519
|
* @see https://github.com/pinojs/pino/blob/master/docs/asynchronous.md
|
|
511
520
|
*/
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
521
|
+
function logAndWait(msg) {
|
|
522
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
+
logger.error(msg);
|
|
524
|
+
chai_1.assert.isFunction(logger[`pino`][`flush`], `The "flush method should exist on a Pino logger"`);
|
|
525
|
+
logger[`pino`][`flush`]();
|
|
526
|
+
const max = 5000;
|
|
527
|
+
let elapsed = 0;
|
|
528
|
+
const sleep = 200;
|
|
529
|
+
while (!fs.existsSync(testingLogFile) && elapsed < max) {
|
|
530
|
+
yield general_utils_1.utils.sleep(sleep);
|
|
531
|
+
elapsed += sleep;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
523
534
|
}
|
|
524
|
-
it('No log file - default',
|
|
535
|
+
it('No log file - default', () => __awaiter(this, void 0, void 0, function* () {
|
|
525
536
|
loggerConfig = new configs_1.LoggerConfigs(() => TESTING_CID);
|
|
526
537
|
loggerConfig.setLogHumanReadableinConsole(false);
|
|
527
538
|
loggerConfig.setLogSource(true);
|
|
528
539
|
loggerConfig.setLogLevel(logger_1.LogLevel.DEBUG);
|
|
529
540
|
loggerConfig.setLogDirectory(testingLogDir);
|
|
530
|
-
logger_1.initLogger(loggerConfig, 'default', true);
|
|
541
|
+
(0, logger_1.initLogger)(loggerConfig, 'default', true);
|
|
531
542
|
logger = new logger_1.Logger('test');
|
|
532
|
-
|
|
543
|
+
yield logAndWait('allo');
|
|
533
544
|
chai_1.assert.isFalse(fs.existsSync(testingLogFile));
|
|
534
|
-
});
|
|
535
|
-
it('No log file - explicit',
|
|
545
|
+
}));
|
|
546
|
+
it('No log file - explicit', () => __awaiter(this, void 0, void 0, function* () {
|
|
536
547
|
loggerConfig = new configs_1.LoggerConfigs(() => TESTING_CID);
|
|
537
548
|
loggerConfig.setLogHumanReadableinConsole(false);
|
|
538
549
|
loggerConfig.setLogSource(true);
|
|
539
550
|
loggerConfig.setLogLevel(logger_1.LogLevel.DEBUG);
|
|
540
551
|
loggerConfig.setLogDirectory(testingLogDir);
|
|
541
552
|
loggerConfig.setSlowerLogToFileToo(false);
|
|
542
|
-
logger_1.initLogger(loggerConfig, 'default', true);
|
|
553
|
+
(0, logger_1.initLogger)(loggerConfig, 'default', true);
|
|
543
554
|
logger = new logger_1.Logger('test');
|
|
544
|
-
|
|
555
|
+
yield logAndWait('allo');
|
|
545
556
|
chai_1.assert.isFalse(fs.existsSync(testingLogFile));
|
|
546
|
-
});
|
|
547
|
-
it('Log file',
|
|
557
|
+
}));
|
|
558
|
+
it('Log file', () => __awaiter(this, void 0, void 0, function* () {
|
|
548
559
|
loggerConfig = new configs_1.LoggerConfigs(() => TESTING_CID);
|
|
549
560
|
loggerConfig.setLogHumanReadableinConsole(false);
|
|
550
561
|
loggerConfig.setLogSource(true);
|
|
551
562
|
loggerConfig.setLogLevel(logger_1.LogLevel.DEBUG);
|
|
552
563
|
loggerConfig.setLogDirectory(testingLogDir);
|
|
553
564
|
loggerConfig.setSlowerLogToFileToo(true);
|
|
554
|
-
logger_1.initLogger(loggerConfig, 'default', true);
|
|
565
|
+
(0, logger_1.initLogger)(loggerConfig, 'default', true);
|
|
555
566
|
logger = new logger_1.Logger('test');
|
|
556
|
-
|
|
567
|
+
yield logAndWait('allo');
|
|
557
568
|
chai_1.assert.isTrue(fs.existsSync(testingLogFile));
|
|
558
569
|
const content = fs.readFileSync(testingLogFile, 'utf-8');
|
|
559
570
|
chai_1.assert.isOk(content);
|
|
560
571
|
chai_1.assert.isTrue(content.indexOf(`"msg":"allo"`) > -1);
|
|
561
|
-
});
|
|
572
|
+
}));
|
|
562
573
|
});
|
|
563
574
|
});
|
|
564
575
|
//# sourceMappingURL=logger.test.js.map
|