zeddemore-logger 2.1.2 → 2.2.3

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # zeddemore-logger
2
2
 
3
- Node.js logger using Morgan and Winston and CLI-Progress.
3
+ Node.js Express logger using Morgan and Winston for thread and caller info tracking.
@@ -6,7 +6,7 @@ const { DateTime } = require('luxon');
6
6
 
7
7
  const { convertFechaDateFormatToLuxon } = require('./date');
8
8
  const defaults = require('./defaults');
9
- const { isValidLogLevel, logLevelToWinstonLogLevelName } = require('./logging');
9
+ const { isWinstonLogLevel, winstonLogLevelName } = require('./logging');
10
10
  const { stringToIdempotentHexColor } = require('./color');
11
11
  require('./typedef');
12
12
 
@@ -107,7 +107,7 @@ class ZeddemoreBase {
107
107
  }
108
108
 
109
109
  set defaultUserLogLevel(level) {
110
- if (isValidLogLevel(level)) this.#defaultUserLogLevel = logLevelToWinstonLogLevelName(level);
110
+ if (isWinstonLogLevel(level)) this.#defaultUserLogLevel = winstonLogLevelName(level);
111
111
  }
112
112
 
113
113
  get forceLogLevel() {
@@ -124,11 +124,11 @@ class ZeddemoreBase {
124
124
  }
125
125
 
126
126
  set logLevel(level) {
127
- if (isValidLogLevel(level)) this.#logLevel = logLevelToWinstonLogLevelName(level);
127
+ if (isWinstonLogLevel(level)) this.#logLevel = winstonLogLevelName(level);
128
128
  }
129
129
 
130
130
  get logLevelName() {
131
- return logLevelToWinstonLogLevelName(this.logLevel);
131
+ return winstonLogLevelName(this.logLevel);
132
132
  }
133
133
 
134
134
  get luxonTimestampFormat() {
@@ -16,17 +16,16 @@ const enums = require('./enums');
16
16
  const { extractHttpStatusCode, extractHttpVerb } = require('./http');
17
17
  const { extractToken, getRequestResponseTime, isRequestOfMethod, parseRequest } = require('./request');
18
18
  const { generateUuid } = require('./uuid');
19
- const { isMorganFormat, isValidLogLevelId, isWinstonTransportId, logLevelToWinstonLogLevelName, monkeyPatchConsole } = require('./logging');
19
+ const { isMorganFormat, isWinstonFormat, isWinstonLogLevelId, isWinstonTransport, monkeyPatchConsole, transportLogLevelType,
20
+ winstonLogLevelName } = require('./logging');
20
21
  require('./typedef');
21
22
  const WinstonEmailTransport = require('./transports/WinstonEmailTransport');
22
23
  const ZeddemoreBase = require('./ZeddemoreBase');
23
24
  const ZeddemoreLoggerController = require('./ZeddemoreLoggerController');
24
- const ZeddemoreProgressMultibar = require('./ZeddemoreProgressMultibar');
25
25
 
26
- const { createLogger: createWinstonLogger, format, Logform: Format, transports } = winston;
27
- const { colorize, combine, label, metadata, printf, timestamp } = format;
28
- const { httpMethods: http, httpRequestHeaders: rqh, httpResponseHeaders: rsh, morganFormats: mf, morganFormatTokens: mft,
29
- winstonLogLevelNames: wlln, winstonLogLevels: wll, winstonTransportIds: wti } = enums;
26
+ const { createLogger: createWinstonLogger, format: winstonFormat, Logform: Format, transports } = winston;
27
+ const { httpMethods: http, httpRequestHeaders: rqh, httpResponseHeaders: rsh, logLevelTypes: llt, morganFormats: mf,
28
+ morganFormatTokens: mft, winstonFormats: wf, winstonLogLevelNames: wlln, winstonLogLevels: wll, winstonTransports: wt } = enums;
30
29
 
31
30
  class ZeddemoreLogger extends ZeddemoreBase {
32
31
 
@@ -200,7 +199,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
200
199
  }
201
200
 
202
201
  set emailLogLevel(level) {
203
- if (isValidLogLevelId(level)) this.#emailLogLevel = level;
202
+ if (isWinstonLogLevelId(level)) this.#emailLogLevel = level;
204
203
  }
205
204
 
206
205
  get emailLogPassword() {
@@ -260,7 +259,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
260
259
  }
261
260
 
262
261
  get logger() {
263
- if (!(this.#logger instanceof ZeddemoreLoggerController)) this.#logger = this.createLogger();
262
+ if (!(this.#logger instanceof ZeddemoreLoggerController)) this.#logger = this.createLoggerController();
264
263
  return this.#logger;
265
264
  }
266
265
 
@@ -421,46 +420,21 @@ class ZeddemoreLogger extends ZeddemoreBase {
421
420
  return (_.compact(_morganTokens)).join(' ');
422
421
  }
423
422
 
424
- /**
425
- * Build a ZeddemoreProgressBars info
426
- * @param {Object} options
427
- * @returns {Object}
428
- */
429
- #buildProgressInfo = (options) => {
430
- options = options || { };
431
- const label = options.label || this.defaultLabel;
432
- return {
433
- ...options,
434
- colorize: this.colorize,
435
- label,
436
- timestampFormat: this.luxonTimestampFormat,
437
- };
438
- }
439
-
440
423
  /**
441
424
  * Build a Winston format
442
425
  * @param {Object} options
443
- * @param {[Format]} [additionalFormats]
444
- * @param {String} [transportId]
426
+ * @param {[Format|String]} [additionalFormats]
445
427
  * @returns {Format}
446
428
  */
447
- #buildWinstonFormat = (options, additionalFormats = [ ], transportId = null) => {
448
- options = options || { };
449
- const formats = [
450
- format((info) => {
451
- if (isWinstonTransportId(transportId) && isWinstonTransportId(info.transport) && (info.transport !== transportId)) return false;
452
- info.id = info.id || options.id || null;
453
- info.ip = info.ip || options.ip || null;
454
- info.user = info.user || options.user || null;
455
- return info;
456
- })(),
457
- colorize(),
458
- label({ label: options.label || this.defaultLabel }),
459
- timestamp({ format: this.winstonTimestampFormat }),
460
- metadata(),
461
- printf(this.#buildWinstonTemplate),
462
- ];
463
- return combine(...additionalFormats.concat(formats));
429
+ #buildWinstonFormat = (options, additionalFormats = [ ]) => {
430
+ additionalFormats = _.isArray(additionalFormats) ? additionalFormats : [ additionalFormats ];
431
+ const formats = this.#getDefaultFormats(options);
432
+ const _additionalFormats = _.compact(additionalFormats.map((format) => {
433
+ if (isWinstonFormat(format)) return this.#getBuiltinFormat(format, options);
434
+ if (_.isFunction(format)) return format;
435
+ return null;
436
+ }));
437
+ return winstonFormat.combine(..._additionalFormats.concat(formats));
464
438
  }
465
439
 
466
440
  /**
@@ -481,30 +455,22 @@ class ZeddemoreLogger extends ZeddemoreBase {
481
455
  /**
482
456
  * Build a Winston Console transport
483
457
  * @param {number|String} [logLevel]
484
- * @param {Object} [options]
485
- * @param {[Format]} [options.formats]
486
458
  * @returns {winston.ConsoleTransportInstance}
487
459
  */
488
- #buildWinstonConsoleTransport = (logLevel = this.logLevel, options) => {
489
- options = options || { };
460
+ #buildWinstonConsoleTransport = (logLevel = this.logLevel) => {
490
461
  logLevel = logLevel || this.logLevel;
491
- const level = logLevelToWinstonLogLevelName(logLevel);
492
- const format = this.#buildWinstonFormat(options, options.formats, wti.CONSOLE);
493
- return new transports.Console({ format, id: wti.CONSOLE, level });
462
+ const level = winstonLogLevelName(logLevel);
463
+ return new transports.Console({ id: wt.CONSOLE, level });
494
464
  }
495
465
 
496
466
  /**
497
467
  * Build a Winston Email transport
498
468
  * @param {number|String} [logLevel]
499
- * @param {Object} [options]
500
- * @param {[Format]} [options.formats]
501
469
  * @returns {WinstonEmailTransport}
502
470
  */
503
- #buildWinstonEmailTransport = (logLevel = this.emailLogLevel, options) => {
504
- options = options || { };
471
+ #buildWinstonEmailTransport = (logLevel = this.emailLogLevel) => {
505
472
  logLevel = logLevel || this.emailLogLevel;
506
- const level = logLevelToWinstonLogLevelName(logLevel);
507
- const format = this.#buildWinstonFormat(options, options.formats, wti.EMAIL);
473
+ const level = winstonLogLevelName(logLevel);
508
474
  const messageOptions = {
509
475
  from: this.emailLogFrom,
510
476
  subject: this.emailLogSubject,
@@ -520,22 +486,22 @@ class ZeddemoreLogger extends ZeddemoreBase {
520
486
  port: this.emailLogPort,
521
487
  };
522
488
  const winstonOptions = { level };
523
- const _options = { format, id: wti.EMAIL, messageOptions, transportOptions, ...winstonOptions };
489
+ const _options = { id: wt.EMAIL, messageOptions, transportOptions, ...winstonOptions };
524
490
  return new WinstonEmailTransport(_options);
525
491
  }
526
492
 
527
493
  /**
528
494
  * Build Winston transports
529
- * @param {number|String} [logLevel]
530
- * @param {number|String} [emailLogLevel]
531
- * @param {[Object]} [additionalTransports]
495
+ * @param {[Object|String]} [transports]
532
496
  * @returns {Object[]}
533
497
  */
534
- #buildWinstonTransports = (logLevel = this.logLevel, emailLogLevel = this.emailLogLevel, additionalTransports = [ ]) => {
535
- additionalTransports = _.isArray(additionalTransports) ? additionalTransports : [ ];
536
- if (this.doConsoleLog) additionalTransports = additionalTransports.concat([ this.#buildWinstonConsoleTransport(logLevel) ]);
537
- if (this.doEmailLog && this.canEmailLog) additionalTransports = additionalTransports.concat([ this.#buildWinstonEmailTransport(emailLogLevel) ]);
538
- return additionalTransports;
498
+ #buildWinstonTransports = (transports = [ ]) => {
499
+ transports = _.compact(_.isArray(transports) ? transports : [ transports ]);
500
+ return _.compact(transports.map((transport) => {
501
+ if (isWinstonTransport(transport)) return this.#getBuiltinTransport(transport);
502
+ if (_.isObject(transport)) return transport;
503
+ return null;
504
+ }));
539
505
  }
540
506
 
541
507
  #colorizeResponse(message) {
@@ -543,19 +509,31 @@ class ZeddemoreLogger extends ZeddemoreBase {
543
509
  return verb ? chalkHttpVerbs(verb, message) : message;
544
510
  }
545
511
 
512
+ createLogger = (options) => {
513
+ return this.createLoggerController(options);
514
+ }
515
+
546
516
  /**
547
517
  * Create a ZeddemoreLoggerController
548
518
  * @param {Object} [options]
549
- * @param {[Format]} [options.formats]
550
- * @param {String} [options.level]
551
- * @param {[Object]} [options.transports]
519
+ * @param {[Format|String]} [options.formats]
520
+ * @param {[Object|String]} [options.transports]
552
521
  * @returns {ZeddemoreLoggerController}
553
522
  */
554
- createLogger = (options) => {
523
+ #createLoggerController = (options) => {
555
524
  options = options || { };
556
- const winstonLogger = this.#createWinstonLogger(options);
557
- const multiBar = this.#createZeddemoreProgressMultibar(options);
558
- this.#logger = new ZeddemoreLoggerController({ logger: winstonLogger, progress: multiBar });
525
+ const transports = _.compact(_.isArray(options.winstonTransports) ? options.winstonTransports : [ options.winstonTransports ]);
526
+ const defaultLoggerTransports = transports.concat(this.#getDefaultTransports());
527
+ const defaultLogger = this.#createWinstonLogger({ transports: defaultLoggerTransports, ...options });
528
+ const loggers = { logger: defaultLogger };
529
+ if (this.doEmailLog && this.canEmailLog) {
530
+ loggers.emailLogger = this.#createWinstonLogger({ transports: [ wt.EMAIL ], ...options });
531
+ }
532
+ return new ZeddemoreLoggerController(loggers);
533
+ }
534
+
535
+ createLoggerController = (options) => {
536
+ this.#logger = this.#createLoggerController(options);
559
537
  return this.#logger;
560
538
  }
561
539
 
@@ -570,7 +548,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
570
548
  /** @type {Object} */
571
549
  const loggerOptions = { id: requestId };
572
550
  if (ipAddress) loggerOptions.ip = ipAddress;
573
- return this.createLogger(loggerOptions);
551
+ return this.createLoggerController(loggerOptions);
574
552
  }
575
553
 
576
554
  /**
@@ -586,31 +564,21 @@ class ZeddemoreLogger extends ZeddemoreBase {
586
564
  logLevel = logLevel || this.defaultUserLogLevel;
587
565
  const loggerOptions = { id: requestId, level: logLevel, user: username };
588
566
  if (ipAddress) loggerOptions.ip = ipAddress;
589
- return this.createLogger(loggerOptions);
567
+ return this.createLoggerController(loggerOptions);
590
568
  }
591
569
 
592
570
  /**
593
571
  * Create a Winston Logger
594
572
  * @param {Object} [options]
595
- * @param {[Format]} [options.formats]
596
- * @param {number|String} [options.level]
597
- * @param {number|String} [options.emailLevel]
598
- * @param {[Object]} [options.transports]
573
+ * @param {[Format|string]} [options.formats]
574
+ * @param {[Object|String]} [options.transports]
599
575
  * @returns {winston.Logger}
600
576
  */
601
577
  #createWinstonLogger = (options) => {
602
578
  options = options || { };
603
- const transports = this.#buildWinstonTransports(options.level, options.emailLevel, options.transports);
604
- return createWinstonLogger({ transports });
605
- }
606
-
607
- /**
608
- * Create a progress MultiBar
609
- * @param {Object} [options]
610
- * @returns {ZeddemoreProgressMultibar}
611
- */
612
- #createZeddemoreProgressMultibar = (options) => {
613
- return new ZeddemoreProgressMultibar(this.#buildProgressInfo(options));
579
+ const format = this.#buildWinstonFormat(options, options.formats);
580
+ const transports = this.#buildWinstonTransports(options.transports);
581
+ return createWinstonLogger({ format, transports });
614
582
  }
615
583
 
616
584
  /**
@@ -633,13 +601,66 @@ class ZeddemoreLogger extends ZeddemoreBase {
633
601
  monkeyPatchConsole(methodNames, colors, depth, showHidden);
634
602
  }
635
603
 
604
+ #formatInfoMutation(options) {
605
+ return winstonFormat((info) => {
606
+ info.id = info.id || options.id || null;
607
+ info.ip = info.ip || options.ip || null;
608
+ info.user = info.user || options.user || null;
609
+ return info;
610
+ });
611
+ }
612
+
613
+ #getBuiltinFormat(format, options) {
614
+ options = options || { };
615
+ switch (format) {
616
+ case wf.COLORIZE: return winstonFormat.colorize();
617
+ case wf.JSON: return winstonFormat.json();
618
+ case wf.METADATA: return winstonFormat.metadata();
619
+ case wf.PRETTY_PRINT: return winstonFormat.prettyPrint();
620
+ case wf.SIMPLE: return winstonFormat.simple();
621
+ case wf.SPLAT: return winstonFormat.splat();
622
+ case wf.TIMESTAMP: return winstonFormat.timestamp();
623
+ case wf.ZEDDEMORE_INFO_MUTATION: return this.#formatInfoMutation(options)();
624
+ case wf.ZEDDEMORE_LABEL: return winstonFormat.label({ label: options.label || this.defaultLabel });
625
+ case wf.ZEDDEMORE_PRINTF: return winstonFormat.printf(this.#buildWinstonTemplate);
626
+ case wf.ZEDDEMORE_TIMESTAMP: return winstonFormat.timestamp({ format: this.winstonTimestampFormat });
627
+ }
628
+ }
629
+
630
+ #getBuiltinTransport(transport) {
631
+ let logLevel = this.logLevel;
632
+ const logLevelType = transportLogLevelType(transport);
633
+ switch (logLevelType) {
634
+ case llt.CONSOLE: logLevel = this.logLevel; break;
635
+ case llt.EMAIL: logLevel = this.emailLogLevel; break;
636
+ }
637
+ switch (transport) {
638
+ case wt.CONSOLE: return this.#buildWinstonConsoleTransport(logLevel);
639
+ case wt.EMAIL: return this.#buildWinstonEmailTransport(logLevel);
640
+ }
641
+ }
642
+
643
+ #getDefaultFormats(options) {
644
+ return _.compact(defaults.winstonFormats.map((format) => this.#getBuiltinFormat(format, options)));
645
+ }
646
+
647
+ #getDefaultTransports() {
648
+ return _.compact(defaults.winstonTransports.map((transport) => {
649
+ switch (transport) {
650
+ case wt.CONSOLE: return this.doConsoleLog ? wt.CONSOLE : null;
651
+ case wt.EMAIL: return (this.doEmailLog && this.canEmailLog) ? wt.EMAIL : null;
652
+ default: return transport;
653
+ }
654
+ }));
655
+ }
656
+
636
657
  /**
637
- * Get a Zeddemore Logger wrapper instance
658
+ * Get a Zeddemore Logger wrapper instance with all transports
638
659
  * @param {Object} options
639
- * @param {[Format]} [options.formats]
660
+ * @param {[Format|String]} [options.formats]
640
661
  * @param {String} [options.level]
641
662
  * @param {ZeddemoreLoggerController} [options.logger]
642
- * @param {[Object]} [options.transports]
663
+ * @param {[Object|String]} [options.transports]
643
664
  * @param {Object} [options.user]
644
665
  * @returns {ZeddemoreLoggerController}
645
666
  */
@@ -647,25 +668,9 @@ class ZeddemoreLogger extends ZeddemoreBase {
647
668
  options = options || { };
648
669
  /** @type {app} app */
649
670
  const logger = options.logger || (options.user ? options.user.logger : null) || ((app && app.locals) ? app.locals.logger : null);
650
- if (!!logger) return logger;
671
+ if (logger instanceof ZeddemoreLoggerController) return logger;
651
672
  const zeddemoreLogger = new ZeddemoreLogger(options);
652
- return zeddemoreLogger.createLogger(options);
653
- }
654
-
655
- /**
656
- * Get a Winston Logger instance
657
- * @param {Object} options
658
- * @param {ZeddemoreProgressBars} [options.progress]
659
- * @param {Object} [options.user]
660
- * @returns {ZeddemoreProgressBars}
661
- */
662
- static getProgress(options) {
663
- options = options || { };
664
- /** @type {app} */
665
- const progress = options.progress || (options.user ? options.user.progress : null) || ((app && app.locals) ? app.locals.progress : null);
666
- if (!!progress) return progress;
667
- const zeddemoreLogger = new ZeddemoreLogger();
668
- return zeddemoreLogger.#createZeddemoreProgressMultibar(options);
673
+ return zeddemoreLogger.createLoggerController(options);
669
674
  }
670
675
 
671
676
  /**
@@ -715,7 +720,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
715
720
  */
716
721
  log = (logLevel) => {
717
722
  logLevel = logLevel || this.logLevel;
718
- const logLevelName = logLevelToWinstonLogLevelName(logLevel);
723
+ const logLevelName = winstonLogLevelName(logLevel);
719
724
  return this.logger[ logLevelName ];
720
725
  }
721
726
 
@@ -776,7 +781,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
776
781
  return `${ packageName }@${ _package.version }`;
777
782
  }
778
783
  const versionParts = _.compact(_.sortBy(packages, (_package) => _package.name.toUpperCase()).map(buildVersionLabel));
779
- this.log(logLevel)(`Packages: ${ versionParts.join(' | ') }`);
784
+ this.log(logLevel)(`Packages: [ ${ versionParts.join(', ') } ]`);
780
785
  }
781
786
 
782
787
  /**
@@ -797,7 +802,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
797
802
  const msgParts = [ `${ routes.length } ${ routesLabel } ${ addedLabel }` ];
798
803
  if (showCategories) {
799
804
  const categories = options.categories || this.apiRouteCategories || [];
800
- msgParts.push(`in: ${ categories.sort().join('/') }`);
805
+ msgParts.push(`in: [ ${ categories.sort().join(', ') } ]`);
801
806
  }
802
807
  this.log(logLevel)(msgParts.join(', '));
803
808
  }
@@ -869,11 +874,12 @@ class ZeddemoreLogger extends ZeddemoreBase {
869
874
  const user = this.userGetFn(req, res);
870
875
  if (user) logOptions.user = user;
871
876
  const response = colorize ? this.#colorizeResponse(message.trim()) : message.trim();
872
- ZeddemoreLogger.getLogger(logOptions).http(response);
873
- if (this.doEmailLog) {
877
+ const logger = ZeddemoreLogger.getLogger(logOptions);
878
+ logger.http(response);
879
+ if (this.doEmailLog && this.canEmailLog) {
874
880
  const statusCode = extractHttpStatusCode(message);
875
881
  if (isResponseFailure(statusCode, [ 404 ])) {
876
- ZeddemoreLogger.getLogger(logOptions).log({ level: wlln.ERROR, message: response, transport: wti.EMAIL });
882
+ logger.logEmail({ level: wlln.ERROR, message: response });
877
883
  }
878
884
  }
879
885
  },
@@ -1024,7 +1030,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
1024
1030
  const _request = axiosResponse.request;
1025
1031
  const axiosConfig = logOptions.axios || { };
1026
1032
  const configData = (logOptions.data && _.isObject(axiosConfig.data)) ? JSON.stringify(axiosConfig.data) : null;
1027
- const logLevel = logLevelToWinstonLogLevelName(logOptions.logLevel);
1033
+ const logLevel = winstonLogLevelName(logOptions.logLevel);
1028
1034
  const logger = options.logger || ZeddemoreLogger.getLogger(options);
1029
1035
  if (!logger) return;
1030
1036
  const _method = _request.method || null;
@@ -4,22 +4,35 @@ const _ = require('lodash');
4
4
  const winston = require('winston');
5
5
 
6
6
  const enums = require('./enums');
7
- const ZeddemoreProgressMultibar = require('./ZeddemoreProgressMultibar');
8
7
 
9
8
  const { Logger } = winston;
10
9
  const { winstonLogLevelNames: wlln } = enums;
11
10
 
12
11
  class ZeddemoreLoggerController {
13
12
 
14
- /** @type {ZeddemoreProgressMultibar} */
15
- #multiBar = null;
13
+ /** @type {winston.Logger} */
14
+ #winstonEmailLogger = null;
16
15
  /** @type {winston.Logger} */
17
16
  #winstonLogger = null;
18
17
 
19
18
  constructor(options) {
20
19
  options = options || { };
21
20
  this.logger = options.logger;
22
- this.progress = options.progress;
21
+ this.emailLogger = options.emailLogger;
22
+ }
23
+
24
+ get emailLogger() {
25
+ return this.#winstonEmailLogger;
26
+ }
27
+
28
+ set emailLogger(value) {
29
+ if (value instanceof Logger) {
30
+ this.#winstonEmailLogger = value;
31
+ }
32
+ }
33
+
34
+ get hasWinstonEmailLogger() {
35
+ return (this.#winstonEmailLogger instanceof Logger);
23
36
  }
24
37
 
25
38
  get hasWinstonLogger() {
@@ -33,24 +46,16 @@ class ZeddemoreLoggerController {
33
46
  set logger(value) {
34
47
  if (value instanceof Logger) {
35
48
  this.#winstonLogger = value;
36
- this.#buildWinstonLogLevelFunctions();
49
+ this.#buildWinstonLogLevelFunctions(this.#winstonLogger);
37
50
  }
38
51
  }
39
52
 
40
- get progress() {
41
- return this.#multiBar;
42
- }
43
-
44
- set progress(value) {
45
- if (value instanceof ZeddemoreProgressMultibar) this.#multiBar = value;
46
- }
47
-
48
- #buildWinstonLogLevelFunctions() {
49
- if (!this.hasWinstonLogger) return;
53
+ #buildWinstonLogLevelFunctions(logger) {
54
+ if (!(logger instanceof Logger)) return
50
55
  for (const levelName of Object.values(wlln)) {
51
- if (_.isFunction(this.#winstonLogger[ levelName ])) {
56
+ if (_.isFunction(logger[ levelName ])) {
52
57
  this[ levelName ] = (...args) => {
53
- this.#winstonLogger[ levelName ](...args);
58
+ logger[ levelName ](...args);
54
59
  }
55
60
  } else {
56
61
  this[ levelName ] = () => this.#noop();
@@ -68,6 +73,11 @@ class ZeddemoreLoggerController {
68
73
  return this.#noop()
69
74
  }
70
75
 
76
+ logEmail = (options) => {
77
+ if (this.hasWinstonEmailLogger) return this.#winstonEmailLogger.log(options);
78
+ return this.#noop()
79
+ }
80
+
71
81
  #noop = () => {
72
82
  // No operation function, used to prevent errors when logger methods are called but no logger is set.
73
83
  }
package/lib/defaults.js CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  const enums = require('./enums');
4
4
 
5
- const { hexColors: hc, morganFormats: mf, morganFormatTokens: mft, winstonLogLevelNames: wlln } = enums;
5
+ const { hexColors: hc, logLevelTypes: llt, morganFormats: mf, morganFormatTokens: mft, winstonFormats: wf,
6
+ winstonLogLevelNames: wlln, winstonTransports: wt } = enums;
6
7
 
7
8
  module.exports = {
8
9
  colorConsoleWhiteHex: hc.CONSOLE_WHITE,
@@ -10,28 +11,18 @@ module.exports = {
10
11
  consoleDirExtensionColors: true,
11
12
  consoleDirExtensionDepth: null,
12
13
  consoleDirExtensionShowHidden: true,
13
- consoleTransportName: 'console',
14
14
  contentLengthDigits: 2,
15
15
  liveMessage: '⚡live⚡',
16
+ logLevelType: llt.CONSOLE,
16
17
  morganFormat: mf.ZEDDEMORE,
17
18
  morganFormatTokens: [ mft.METHOD, mft.DECODED_URL, mft.STATUS, mft.RESPONSE_TIME_FORMAT, mft.CONTENT_LENGTH_FORMAT ],
18
19
  morganFormatTokensColorized: [ mft.METHOD, mft.DECODED_URL, mft.STATUS_COLORED, mft.RESPONSE_TIME_FORMAT, mft.CONTENT_LENGTH_FORMAT ],
19
- progressBarBarFormat: '{bar}',
20
- progressBarCompleteCharacter: '█',
21
- progressBarDelimiter: '|',
22
- progressBarDurationFormat: '{duration}s',
23
- progressBarDurationFormattedFormat: '{duration_formatted}',
24
- progressBarEtaFormat: '{eta}s',
25
- progressBarEtaFormattedFormat: '{eta_formatted}',
26
- progressBarIncompleteCharacter: '░',
27
- progressBarPercentageFormat: '{percentage}%',
28
- progressBarPostfixFormat: '{postfix}',
29
- progressBarValueFormat: '{value}',
30
- progressBarTotalFormat: '{total}',
31
20
  requestIdAttribute: 'requestId',
32
21
  requestIdIcon: '🧵',
33
22
  responseTimeDigits: 0,
34
23
  timestampFormat: 'YYYY-MM-DD HH:mm:ss',
35
24
  userLogLevel: -1,
25
+ winstonFormats: [ wf.ZEDDEMORE_INFO_MUTATION, wf.COLORIZE, wf.ZEDDEMORE_LABEL, wf.ZEDDEMORE_TIMESTAMP, wf.METADATA, wf.ZEDDEMORE_PRINTF ],
26
+ winstonTransports: [ wt.CONSOLE, wt.EMAIL ],
36
27
  winstonLogLevelName: wlln.INFO,
37
28
  };