@cichol/logger 4.0.0 → 4.2.2
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/package.json +11 -10
- package/releases/cjs.js +130 -161
- package/releases/esm.js +92 -96
- package/types/classes/logger.d.ts +0 -33
- package/types/formatters/command-line.d.ts +0 -2
- package/types/formatters/morgan.d.ts +0 -8
- package/types/handlers/debug.d.ts +0 -5
- package/types/handlers/error.d.ts +0 -13
- package/types/handlers/fatal.d.ts +0 -4
- package/types/handlers/http.d.ts +0 -5
- package/types/handlers/index.d.ts +0 -12
- package/types/handlers/info.d.ts +0 -5
- package/types/handlers/notice.d.ts +0 -5
- package/types/handlers/query.d.ts +0 -13
- package/types/handlers/verbose.d.ts +0 -5
- package/types/handlers/warning.d.ts +0 -5
- package/types/helpers/color-scheme.d.ts +0 -12
- package/types/helpers/constants.d.ts +0 -18
- package/types/helpers/label-decorator.d.ts +0 -2
- package/types/helpers/logging-level.d.ts +0 -13
- package/types/index.d.ts +0 -1
package/releases/esm.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import _Symbol from '
|
|
2
|
-
import _filterInstanceProperty from '
|
|
3
|
-
import _mapInstanceProperty from '
|
|
4
|
-
import _trimInstanceProperty from '
|
|
5
|
-
import _Reflect$hasOwnMetadata from '@babel/runtime-corejs3/core-js/reflect/has-own-metadata';
|
|
6
|
-
import _Reflect$getOwnMetadata from '@babel/runtime-corejs3/core-js/reflect/get-own-metadata';
|
|
7
|
-
import _Reflect$defineMetadata from '@babel/runtime-corejs3/core-js/reflect/define-metadata';
|
|
1
|
+
import _Symbol from 'core-js-pure/stable/symbol/index.js';
|
|
2
|
+
import _filterInstanceProperty from 'core-js-pure/stable/instance/filter.js';
|
|
3
|
+
import _mapInstanceProperty from 'core-js-pure/stable/instance/map.js';
|
|
4
|
+
import _trimInstanceProperty from 'core-js-pure/stable/instance/trim.js';
|
|
8
5
|
import 'reflect-metadata';
|
|
9
6
|
import { STATUS_CODES, IncomingMessage, ServerResponse } from 'http';
|
|
10
7
|
import { PassThrough } from 'stream';
|
|
@@ -13,16 +10,16 @@ import lodash from 'lodash';
|
|
|
13
10
|
import morgan from 'morgan';
|
|
14
11
|
import * as winston from 'winston';
|
|
15
12
|
import { format } from 'winston';
|
|
16
|
-
import _findInstanceProperty from '
|
|
17
|
-
import _Reflect$apply from '
|
|
13
|
+
import _findInstanceProperty from 'core-js-pure/stable/instance/find.js';
|
|
14
|
+
import _Reflect$apply from 'core-js-pure/stable/reflect/apply.js';
|
|
18
15
|
import chalk from 'chalk';
|
|
19
16
|
import rTracer from 'cls-rtracer';
|
|
20
17
|
import { DateTime } from 'luxon';
|
|
21
|
-
import _Map from '
|
|
18
|
+
import _Map from 'core-js-pure/stable/map/index.js';
|
|
22
19
|
import process, { version, env } from 'process';
|
|
23
|
-
import _Symbol$for from '
|
|
24
|
-
import _startsWithInstanceProperty from '
|
|
25
|
-
import _sliceInstanceProperty from '
|
|
20
|
+
import _Symbol$for from 'core-js-pure/stable/symbol/for.js';
|
|
21
|
+
import _startsWithInstanceProperty from 'core-js-pure/stable/instance/starts-with.js';
|
|
22
|
+
import _sliceInstanceProperty from 'core-js-pure/stable/instance/slice.js';
|
|
26
23
|
import path from 'path';
|
|
27
24
|
import highlight from 'cli-highlight';
|
|
28
25
|
import prettyBytes from 'pretty-bytes';
|
|
@@ -47,16 +44,18 @@ const LoggingLevel = {
|
|
|
47
44
|
Debug: 5
|
|
48
45
|
};
|
|
49
46
|
|
|
50
|
-
|
|
47
|
+
// Constants.
|
|
48
|
+
const colorizerMap = new _Map();
|
|
51
49
|
|
|
50
|
+
// Helpers.
|
|
52
51
|
function createScheme(options) {
|
|
53
52
|
const nextIndex = colorizerMap.size;
|
|
54
53
|
const colorizer = chalk.bgHex(options.background).hex(options.foreground);
|
|
55
54
|
colorizerMap.set(nextIndex, colorizer);
|
|
56
55
|
return nextIndex;
|
|
57
|
-
}
|
|
58
|
-
|
|
56
|
+
}
|
|
59
57
|
|
|
58
|
+
// Color definitions.
|
|
60
59
|
const ColorValue = {
|
|
61
60
|
// Basic colors.
|
|
62
61
|
White: '#FFFFFF',
|
|
@@ -98,10 +97,12 @@ const ColorScheme = {
|
|
|
98
97
|
function getChalkOf(colorSet) {
|
|
99
98
|
return colorizerMap.get(colorSet) ?? chalk;
|
|
100
99
|
}
|
|
100
|
+
|
|
101
101
|
/* eslint-enable no-use-before-define */
|
|
102
102
|
|
|
103
103
|
// Node.js built-in APIs.
|
|
104
104
|
|
|
105
|
+
// Constants.
|
|
105
106
|
const {
|
|
106
107
|
isTTY
|
|
107
108
|
} = process.stdout;
|
|
@@ -110,61 +111,51 @@ function decorateLabel(label, scheme) {
|
|
|
110
111
|
if (isNotOnCLI) {
|
|
111
112
|
return label;
|
|
112
113
|
}
|
|
113
|
-
|
|
114
114
|
const chalk = getChalkOf(scheme);
|
|
115
115
|
const decoratedLabel = chalk.bold(` ${label} `);
|
|
116
116
|
return decoratedLabel;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
// Type definitions.
|
|
120
|
+
|
|
119
121
|
// Constants.
|
|
120
122
|
const rootPath = process.cwd();
|
|
121
123
|
const conjunction = ` ${chalk.blue('──')} `;
|
|
124
|
+
const splat = _Symbol$for('splat');
|
|
122
125
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
// Handler metadata.
|
|
126
127
|
const name$8 = 'error';
|
|
127
128
|
const level$8 = LoggingLevel.Error;
|
|
128
129
|
const label$8 = decorateLabel('ERROR', ColorScheme.Critical);
|
|
129
|
-
|
|
130
130
|
function mapLocationOfErrorThrown(filename) {
|
|
131
131
|
let target = path.relative(rootPath, filename);
|
|
132
|
-
|
|
133
132
|
if (_startsWithInstanceProperty(target).call(target, 'node_modules')) {
|
|
134
133
|
target = chalk.gray(target).replace(/node_modules[\\/]([^\\/]+)(.*)/, (matches, moduleName, trailing) => `node_modules${path.sep}${chalk.bold.underline(moduleName)}${chalk.gray(trailing)}` // eslint-disable-line max-len
|
|
135
134
|
);
|
|
136
135
|
} else {
|
|
137
136
|
target = `${chalk.gray(path.dirname(target) + path.sep)}${chalk.bold.underline(path.basename(target))}`;
|
|
138
137
|
}
|
|
139
|
-
|
|
140
138
|
return target;
|
|
141
139
|
}
|
|
142
|
-
|
|
143
140
|
function handle$1(data) {
|
|
144
141
|
var _context, _context2, _context3;
|
|
145
|
-
|
|
146
142
|
const {
|
|
147
143
|
[splat]: [error] = []
|
|
148
144
|
} = data;
|
|
149
|
-
|
|
150
145
|
if (!(error instanceof Error)) {
|
|
151
146
|
return undefined;
|
|
152
147
|
}
|
|
153
|
-
|
|
154
148
|
const {
|
|
155
149
|
name,
|
|
156
150
|
message,
|
|
157
151
|
stack: rawStack = ''
|
|
158
152
|
} = error;
|
|
159
|
-
|
|
160
153
|
const stack = _mapInstanceProperty(_context = _mapInstanceProperty(_context2 = _mapInstanceProperty(_context3 = _sliceInstanceProperty(rawStack).call(rawStack, name.length + message.length + 3).split('\n')).call(_context3, line => line.replace(/^\s+at /g, ''))).call(_context2, line => path.isAbsolute(line) ? `<anonymous>${conjunction}${mapLocationOfErrorThrown(line)}` : line)).call(_context, line => line.replace(/^(.+) \((.+)\)$/, (matches, contextName, rawLocation) => {
|
|
161
154
|
let location;
|
|
162
|
-
|
|
163
155
|
if (rawLocation === '<anonymous>') {
|
|
164
156
|
location = chalk.gray(rawLocation);
|
|
165
157
|
} else {
|
|
166
158
|
const [filename, line, column] = rawLocation.split(':');
|
|
167
|
-
|
|
168
159
|
if (path.isAbsolute(filename)) {
|
|
169
160
|
const target = mapLocationOfErrorThrown(path.relative(rootPath, filename));
|
|
170
161
|
const trailing = chalk.gray(`:${line}:${column}`);
|
|
@@ -173,10 +164,8 @@ function handle$1(data) {
|
|
|
173
164
|
location = chalk.gray(`https://github.com/${chalk.bold.underline('nodejs')}/node/blob/${version}/lib/${filename}#L${line}`); // eslint-disable-line max-len
|
|
174
165
|
}
|
|
175
166
|
}
|
|
176
|
-
|
|
177
167
|
return `${contextName}${conjunction}${location}`;
|
|
178
168
|
})).join('\n');
|
|
179
|
-
|
|
180
169
|
const label = decorateLabel(name, ColorScheme.Critical);
|
|
181
170
|
const payload = `${message}\n\n${stack}\n`;
|
|
182
171
|
return {
|
|
@@ -187,28 +176,30 @@ function handle$1(data) {
|
|
|
187
176
|
|
|
188
177
|
var ErrorHandler = /*#__PURE__*/Object.freeze({
|
|
189
178
|
__proto__: null,
|
|
190
|
-
|
|
191
|
-
level: level$8,
|
|
179
|
+
default: handle$1,
|
|
192
180
|
label: label$8,
|
|
193
|
-
|
|
181
|
+
level: level$8,
|
|
182
|
+
name: name$8
|
|
194
183
|
});
|
|
195
184
|
|
|
196
185
|
// Local helpers.
|
|
197
186
|
|
|
187
|
+
// Handler metadata.
|
|
198
188
|
const name$7 = 'fatal';
|
|
199
189
|
const level$7 = LoggingLevel.Fatal;
|
|
200
190
|
const label$7 = decorateLabel('FATAL', ColorScheme.Critical);
|
|
201
191
|
|
|
202
192
|
var FatalHandler = /*#__PURE__*/Object.freeze({
|
|
203
193
|
__proto__: null,
|
|
204
|
-
|
|
205
|
-
level: level$7,
|
|
194
|
+
default: handle$1,
|
|
206
195
|
label: label$7,
|
|
207
|
-
|
|
196
|
+
level: level$7,
|
|
197
|
+
name: name$7
|
|
208
198
|
});
|
|
209
199
|
|
|
210
200
|
// Local helpers.
|
|
211
201
|
|
|
202
|
+
// Handler metadata.
|
|
212
203
|
const name$6 = 'warning';
|
|
213
204
|
const level$6 = LoggingLevel.Warning;
|
|
214
205
|
const label$6 = decorateLabel('WARNING', ColorScheme.Warning);
|
|
@@ -216,14 +207,15 @@ var warning = null;
|
|
|
216
207
|
|
|
217
208
|
var WarningHandler = /*#__PURE__*/Object.freeze({
|
|
218
209
|
__proto__: null,
|
|
219
|
-
|
|
220
|
-
level: level$6,
|
|
210
|
+
default: warning,
|
|
221
211
|
label: label$6,
|
|
222
|
-
|
|
212
|
+
level: level$6,
|
|
213
|
+
name: name$6
|
|
223
214
|
});
|
|
224
215
|
|
|
225
216
|
// Local helpers.
|
|
226
217
|
|
|
218
|
+
// Handler metadata.
|
|
227
219
|
const name$5 = 'notice';
|
|
228
220
|
const level$5 = LoggingLevel.Notice;
|
|
229
221
|
const label$5 = decorateLabel('NOTICE', ColorScheme.Regular);
|
|
@@ -231,14 +223,15 @@ var notice = null;
|
|
|
231
223
|
|
|
232
224
|
var NoticeHandler = /*#__PURE__*/Object.freeze({
|
|
233
225
|
__proto__: null,
|
|
234
|
-
|
|
235
|
-
level: level$5,
|
|
226
|
+
default: notice,
|
|
236
227
|
label: label$5,
|
|
237
|
-
|
|
228
|
+
level: level$5,
|
|
229
|
+
name: name$5
|
|
238
230
|
});
|
|
239
231
|
|
|
240
232
|
// Local helpers.
|
|
241
233
|
|
|
234
|
+
// Handler metadata.
|
|
242
235
|
const name$4 = 'info';
|
|
243
236
|
const level$4 = LoggingLevel.Info;
|
|
244
237
|
const label$4 = decorateLabel('INFO', ColorScheme.Regular);
|
|
@@ -246,14 +239,15 @@ var info = null;
|
|
|
246
239
|
|
|
247
240
|
var InfoHandler = /*#__PURE__*/Object.freeze({
|
|
248
241
|
__proto__: null,
|
|
249
|
-
|
|
250
|
-
level: level$4,
|
|
242
|
+
default: info,
|
|
251
243
|
label: label$4,
|
|
252
|
-
|
|
244
|
+
level: level$4,
|
|
245
|
+
name: name$4
|
|
253
246
|
});
|
|
254
247
|
|
|
255
248
|
// Local helpers.
|
|
256
249
|
|
|
250
|
+
// Handler metadata.
|
|
257
251
|
const name$3 = 'http';
|
|
258
252
|
const level$3 = LoggingLevel.Http;
|
|
259
253
|
const label$3 = decorateLabel('HTTP', ColorScheme.Http);
|
|
@@ -261,14 +255,16 @@ var http = null;
|
|
|
261
255
|
|
|
262
256
|
var HttpHandler = /*#__PURE__*/Object.freeze({
|
|
263
257
|
__proto__: null,
|
|
264
|
-
|
|
265
|
-
level: level$3,
|
|
258
|
+
default: http,
|
|
266
259
|
label: label$3,
|
|
267
|
-
|
|
260
|
+
level: level$3,
|
|
261
|
+
name: name$3
|
|
268
262
|
});
|
|
269
263
|
|
|
270
264
|
// Highlight.js
|
|
271
265
|
|
|
266
|
+
// Type definitions.
|
|
267
|
+
|
|
272
268
|
// Handler metadata.
|
|
273
269
|
const name$2 = 'query';
|
|
274
270
|
const level$2 = LoggingLevel.Query;
|
|
@@ -285,14 +281,15 @@ function handle(data) {
|
|
|
285
281
|
|
|
286
282
|
var QueryHandler = /*#__PURE__*/Object.freeze({
|
|
287
283
|
__proto__: null,
|
|
288
|
-
|
|
289
|
-
level: level$2,
|
|
284
|
+
default: handle,
|
|
290
285
|
label: label$2,
|
|
291
|
-
|
|
286
|
+
level: level$2,
|
|
287
|
+
name: name$2
|
|
292
288
|
});
|
|
293
289
|
|
|
294
290
|
// Local helpers.
|
|
295
291
|
|
|
292
|
+
// Handler metadata.
|
|
296
293
|
const name$1 = 'verbose';
|
|
297
294
|
const level$1 = LoggingLevel.Verbose;
|
|
298
295
|
const label$1 = decorateLabel('VERBOSE', ColorScheme.Loud);
|
|
@@ -300,14 +297,15 @@ var verbose = null;
|
|
|
300
297
|
|
|
301
298
|
var VerboseHandler = /*#__PURE__*/Object.freeze({
|
|
302
299
|
__proto__: null,
|
|
303
|
-
|
|
304
|
-
level: level$1,
|
|
300
|
+
default: verbose,
|
|
305
301
|
label: label$1,
|
|
306
|
-
|
|
302
|
+
level: level$1,
|
|
303
|
+
name: name$1
|
|
307
304
|
});
|
|
308
305
|
|
|
309
306
|
// Local helpers.
|
|
310
307
|
|
|
308
|
+
// Handler metadata.
|
|
311
309
|
const name = 'debug';
|
|
312
310
|
const level = LoggingLevel.Debug;
|
|
313
311
|
const label = decorateLabel('DEBUG', ColorScheme.Loud);
|
|
@@ -315,10 +313,10 @@ var debug = null;
|
|
|
315
313
|
|
|
316
314
|
var DebugHandler = /*#__PURE__*/Object.freeze({
|
|
317
315
|
__proto__: null,
|
|
318
|
-
|
|
319
|
-
level: level,
|
|
316
|
+
default: debug,
|
|
320
317
|
label: label,
|
|
321
|
-
|
|
318
|
+
level: level,
|
|
319
|
+
name: name
|
|
322
320
|
});
|
|
323
321
|
|
|
324
322
|
// Handler implementations.
|
|
@@ -328,34 +326,30 @@ var formatForCLI = format.printf(data => {
|
|
|
328
326
|
const timestamp = chalk.gray(DateTime.now().toISO({
|
|
329
327
|
includeOffset: true
|
|
330
328
|
}));
|
|
331
|
-
|
|
332
329
|
const handler = _findInstanceProperty(handlers).call(handlers, ({
|
|
333
330
|
name
|
|
334
331
|
}) => name === data.level);
|
|
335
|
-
|
|
336
332
|
const fallback = {
|
|
337
333
|
label: handler?.label,
|
|
338
334
|
payload: data.message
|
|
339
335
|
};
|
|
336
|
+
const performHandle = handler?.default ?? (() => fallback);
|
|
340
337
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
338
|
+
// Execute handler and then, get decorated payload.
|
|
344
339
|
const {
|
|
345
340
|
label,
|
|
346
341
|
payload
|
|
347
342
|
} = _Reflect$apply(performHandle, undefined, [data]) ?? fallback;
|
|
348
343
|
let extraFingerprint;
|
|
349
|
-
|
|
350
344
|
if (handler?.level === LoggingLevel.Http) {
|
|
351
345
|
extraFingerprint = data.transactionId ? `(Transaction-ID = ${data.transactionId})` : `(Request-ID = ${rTracer.id()})`;
|
|
352
346
|
}
|
|
353
|
-
|
|
354
347
|
return `${label} ${timestamp}${extraFingerprint ? ` ${extraFingerprint}` : ''}\n${payload}`;
|
|
355
348
|
});
|
|
356
349
|
|
|
357
350
|
// Node.js built-in APIs.
|
|
358
351
|
|
|
352
|
+
// Type definitions.
|
|
359
353
|
const ExecutionMode = {
|
|
360
354
|
DevelopmentMode: 'development',
|
|
361
355
|
ProductionMode: 'production'
|
|
@@ -370,74 +364,71 @@ cluster.isPrimary ?? cluster.isMaster ? ClusteringMode.MasterProcess : Clusterin
|
|
|
370
364
|
|
|
371
365
|
// Node.js built-in APIs.
|
|
372
366
|
|
|
367
|
+
// Type definitions.
|
|
368
|
+
|
|
373
369
|
// Helpers.
|
|
374
370
|
function decorateStatusCode(statusCode) {
|
|
375
371
|
const groupOfCode = Math.floor(Number(statusCode) / 100) * 100;
|
|
376
372
|
const baseMessage = `${statusCode} ${STATUS_CODES[statusCode]}`;
|
|
377
|
-
|
|
378
373
|
switch (groupOfCode) {
|
|
379
374
|
case 200:
|
|
380
375
|
{
|
|
381
376
|
return chalk.green(baseMessage);
|
|
382
377
|
}
|
|
383
|
-
|
|
384
378
|
case 300:
|
|
385
379
|
{
|
|
386
380
|
return chalk.magenta(baseMessage);
|
|
387
381
|
}
|
|
388
|
-
|
|
389
382
|
case 400:
|
|
390
383
|
case 500:
|
|
391
384
|
{
|
|
392
385
|
return chalk.red(baseMessage);
|
|
393
386
|
}
|
|
394
|
-
|
|
395
387
|
default:
|
|
396
388
|
{
|
|
397
389
|
return chalk.gray(baseMessage);
|
|
398
390
|
}
|
|
399
391
|
}
|
|
400
392
|
}
|
|
401
|
-
|
|
402
393
|
function formatForMorgan(tokens, request, response) {
|
|
403
394
|
function _(token, ...subArgs) {
|
|
404
395
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
405
396
|
return tokens[token](request, response, ...subArgs);
|
|
406
|
-
}
|
|
407
|
-
|
|
397
|
+
}
|
|
408
398
|
|
|
399
|
+
// Raw values.
|
|
409
400
|
const method = _('method');
|
|
410
|
-
|
|
411
401
|
const URL = _('url');
|
|
412
|
-
|
|
413
402
|
const httpVersion = `HTTP/${_('http-version')}`;
|
|
414
403
|
const statusCode = Number(_('status'));
|
|
415
404
|
const contentLength = Number(_('res', 'content-length') ?? -1);
|
|
416
|
-
const responseTime = Number(_('response-time') ?? -1);
|
|
405
|
+
const responseTime = Number(_('response-time') ?? -1);
|
|
417
406
|
|
|
407
|
+
// Decorated values.
|
|
418
408
|
const $method = chalk.bold(method);
|
|
419
409
|
const $version = chalk.rgb(98, 177, 255)(httpVersion);
|
|
420
410
|
const $statusCode = decorateStatusCode(statusCode);
|
|
421
411
|
const $contentLength = contentLength >= 0 ? prettyBytes(contentLength) : '? B';
|
|
422
|
-
const $responseTime = responseTime >= 0 ? prettyMs(responseTime) : '';
|
|
412
|
+
const $responseTime = responseTime >= 0 ? prettyMs(responseTime) : '';
|
|
423
413
|
|
|
414
|
+
// Additional information.
|
|
424
415
|
const metadata = `(${$contentLength}, ${$responseTime})`;
|
|
425
416
|
return [`→ ${$method} ${URL} ${$version}`, `← ${$version} ${$statusCode} ${metadata}`].join('\n');
|
|
426
417
|
}
|
|
427
|
-
|
|
428
418
|
var formatForMorgan$1 = executionMode === ExecutionMode.DevelopmentMode ? formatForMorgan : morgan.combined;
|
|
429
419
|
|
|
430
420
|
var _context, _context2;
|
|
431
421
|
|
|
422
|
+
// Type definitions.
|
|
423
|
+
|
|
432
424
|
// Transports.
|
|
433
425
|
const {
|
|
434
426
|
Console: ConsoleTransport
|
|
435
|
-
} = winston.transports;
|
|
427
|
+
} = winston.transports;
|
|
436
428
|
|
|
429
|
+
// Keys in order to access private properties.
|
|
437
430
|
const KeyOfInstance = _Symbol('@cichol/logger::classes/logger::Instance');
|
|
438
|
-
|
|
439
431
|
const KeyOfPassport = _Symbol('@cichol/logger::classes/logger::Passport');
|
|
440
|
-
|
|
441
432
|
class Logger {
|
|
442
433
|
#logger = winston.createLogger({
|
|
443
434
|
levels: _filterInstanceProperty(_context = _mapInstanceProperty(_context2 = lodash(handlers)).call(_context2, ({
|
|
@@ -457,30 +448,26 @@ class Logger {
|
|
|
457
448
|
this.log('http', _trimInstanceProperty(data).call(data));
|
|
458
449
|
})
|
|
459
450
|
});
|
|
460
|
-
|
|
461
451
|
constructor(passport) {
|
|
462
452
|
if (passport !== KeyOfPassport) {
|
|
463
453
|
throw new ReferenceError('Logger class cannot be constructed in directly');
|
|
464
454
|
}
|
|
465
455
|
}
|
|
466
|
-
|
|
467
456
|
static get instance() {
|
|
468
457
|
if (this !== Logger) {
|
|
469
458
|
throw new ReferenceError('Logger class is not inheritable');
|
|
470
459
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return _Reflect$getOwnMetadata(KeyOfInstance, Logger);
|
|
460
|
+
if (Reflect.hasOwnMetadata(KeyOfInstance, Logger)) {
|
|
461
|
+
return Reflect.getOwnMetadata(KeyOfInstance, Logger);
|
|
474
462
|
}
|
|
475
|
-
|
|
476
463
|
const instance = new Logger(KeyOfPassport);
|
|
477
|
-
|
|
478
464
|
try {
|
|
479
465
|
return instance;
|
|
480
466
|
} finally {
|
|
481
|
-
|
|
467
|
+
Reflect.defineMetadata(KeyOfInstance, instance, Logger);
|
|
482
468
|
}
|
|
483
469
|
}
|
|
470
|
+
|
|
484
471
|
/**
|
|
485
472
|
* Logging message with specific level.
|
|
486
473
|
*
|
|
@@ -489,38 +476,47 @@ class Logger {
|
|
|
489
476
|
* @param args Additional metadata.
|
|
490
477
|
*/
|
|
491
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Logging HTTP I/O.
|
|
481
|
+
*
|
|
482
|
+
* @param request Node.js built-in `IncomingMessage` instance from `http` module.
|
|
483
|
+
* @param response Node.js built-in `ServerResponse` instance from `http` module.
|
|
484
|
+
*/
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Logging errors in detail.
|
|
488
|
+
*
|
|
489
|
+
* @param error
|
|
490
|
+
*/
|
|
492
491
|
|
|
493
492
|
log(...args) {
|
|
494
493
|
const logger = this.#logger;
|
|
495
494
|
const morgan = this.#morgan;
|
|
496
|
-
|
|
497
495
|
switch (true) {
|
|
498
496
|
case args.length >= 2 && args[0] instanceof IncomingMessage && args[1] instanceof ServerResponse:
|
|
499
497
|
{
|
|
500
498
|
const [request, response] = args;
|
|
501
499
|
return Promise$1.fromCallback(callback => morgan(request, response, callback));
|
|
502
500
|
}
|
|
503
|
-
|
|
504
501
|
case args.length >= 1 && args[0] instanceof Error:
|
|
505
502
|
{
|
|
506
|
-
const [error, ...data] = args;
|
|
503
|
+
const [error, ...data] = args;
|
|
507
504
|
|
|
505
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
508
506
|
logger.log('error', error.message, error, ...data);
|
|
509
507
|
return undefined;
|
|
510
508
|
}
|
|
511
|
-
|
|
512
509
|
default:
|
|
513
510
|
{
|
|
514
|
-
const [level, message, ...data] = args;
|
|
511
|
+
const [level, message, ...data] = args;
|
|
515
512
|
|
|
513
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
516
514
|
logger.log(level, message, ...data);
|
|
517
515
|
return undefined;
|
|
518
516
|
}
|
|
519
517
|
}
|
|
520
518
|
}
|
|
521
|
-
|
|
522
519
|
}
|
|
523
|
-
|
|
524
520
|
var logger = Logger.instance;
|
|
525
521
|
|
|
526
522
|
export { logger as default };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import { IncomingMessage as HttpRequest, ServerResponse as HttpResponse } from 'http';
|
|
4
|
-
import Promise from 'bluebird';
|
|
5
|
-
import type { LoggingLevelName } from '../handlers';
|
|
6
|
-
declare class Logger {
|
|
7
|
-
#private;
|
|
8
|
-
private constructor();
|
|
9
|
-
static get instance(): Logger;
|
|
10
|
-
/**
|
|
11
|
-
* Logging message with specific level.
|
|
12
|
-
*
|
|
13
|
-
* @param level
|
|
14
|
-
* @param message
|
|
15
|
-
* @param args Additional metadata.
|
|
16
|
-
*/
|
|
17
|
-
log(level: LoggingLevelName, message: string, ...args: any[]): void;
|
|
18
|
-
/**
|
|
19
|
-
* Logging HTTP I/O.
|
|
20
|
-
*
|
|
21
|
-
* @param request Node.js built-in `IncomingMessage` instance from `http` module.
|
|
22
|
-
* @param response Node.js built-in `ServerResponse` instance from `http` module.
|
|
23
|
-
*/
|
|
24
|
-
log(request: HttpRequest, response: HttpResponse): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Logging errors in detail.
|
|
27
|
-
*
|
|
28
|
-
* @param error
|
|
29
|
-
*/
|
|
30
|
-
log(error: Error): void;
|
|
31
|
-
}
|
|
32
|
-
declare const _default: Logger;
|
|
33
|
-
export default _default;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingMessage as HttpRequest, ServerResponse as HttpResponse } from 'http';
|
|
3
|
-
import morgan from 'morgan';
|
|
4
|
-
declare module 'morgan' {
|
|
5
|
-
const combined: morgan.FormatFn;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: morgan.FormatFn<HttpRequest, HttpResponse>;
|
|
8
|
-
export default _default;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare type LoggingData = {
|
|
2
|
-
level: string;
|
|
3
|
-
message: string;
|
|
4
|
-
} & Record<PropertyKey, any>;
|
|
5
|
-
declare type HandledData = {
|
|
6
|
-
label: string;
|
|
7
|
-
payload: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const name = "error";
|
|
10
|
-
export declare const level: 1;
|
|
11
|
-
export declare const label: "ERROR";
|
|
12
|
-
export default function handle(data: LoggingData): HandledData | undefined;
|
|
13
|
-
export {};
|
package/types/handlers/http.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as FatalHandler from './fatal';
|
|
2
|
-
import * as ErrorHandler from './error';
|
|
3
|
-
import * as WarningHandler from './warning';
|
|
4
|
-
import * as NoticeHandler from './notice';
|
|
5
|
-
import * as InfoHandler from './info';
|
|
6
|
-
import * as HttpHandler from './http';
|
|
7
|
-
import * as QueryHandler from './query';
|
|
8
|
-
import * as VerboseHandler from './verbose';
|
|
9
|
-
import * as DebugHandler from './debug';
|
|
10
|
-
declare const handlers: (typeof FatalHandler | typeof ErrorHandler | typeof WarningHandler | typeof NoticeHandler | typeof InfoHandler | typeof HttpHandler | typeof QueryHandler | typeof VerboseHandler | typeof DebugHandler)[];
|
|
11
|
-
export declare type LoggingLevelName = (typeof handlers extends (infer T)[] ? T : never)['name'];
|
|
12
|
-
export default handlers;
|
package/types/handlers/info.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare type LoggingData = {
|
|
2
|
-
level: string;
|
|
3
|
-
message: string;
|
|
4
|
-
} & Record<PropertyKey, any>;
|
|
5
|
-
declare type HandledData = {
|
|
6
|
-
label: string;
|
|
7
|
-
payload: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const name = "query";
|
|
10
|
-
export declare const level: 4;
|
|
11
|
-
export declare const label: "QUERY";
|
|
12
|
-
export default function handle(data: LoggingData): HandledData | undefined;
|
|
13
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Chalk } from 'chalk';
|
|
2
|
-
declare const ColorScheme: {
|
|
3
|
-
readonly Critical: number;
|
|
4
|
-
readonly Warning: number;
|
|
5
|
-
readonly Regular: number;
|
|
6
|
-
readonly Http: number;
|
|
7
|
-
readonly Query: number;
|
|
8
|
-
readonly Loud: number;
|
|
9
|
-
};
|
|
10
|
-
declare type ColorScheme = typeof ColorScheme[keyof typeof ColorScheme];
|
|
11
|
-
export declare function getChalkOf(colorSet: ColorScheme): Chalk;
|
|
12
|
-
export default ColorScheme;
|