zeddemore-logger 2.1.1 → 2.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/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,28 @@ 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 emailLogger = this.#createWinstonLogger({ transports: [ wt.EMAIL ], ...options });
529
+ return new ZeddemoreLoggerController({ logger: defaultLogger, emailLogger });
530
+ }
531
+
532
+ createLoggerController = (options) => {
533
+ this.#logger = this.#createLoggerController(options);
559
534
  return this.#logger;
560
535
  }
561
536
 
@@ -570,7 +545,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
570
545
  /** @type {Object} */
571
546
  const loggerOptions = { id: requestId };
572
547
  if (ipAddress) loggerOptions.ip = ipAddress;
573
- return this.createLogger(loggerOptions);
548
+ return this.createLoggerController(loggerOptions);
574
549
  }
575
550
 
576
551
  /**
@@ -586,31 +561,21 @@ class ZeddemoreLogger extends ZeddemoreBase {
586
561
  logLevel = logLevel || this.defaultUserLogLevel;
587
562
  const loggerOptions = { id: requestId, level: logLevel, user: username };
588
563
  if (ipAddress) loggerOptions.ip = ipAddress;
589
- return this.createLogger(loggerOptions);
564
+ return this.createLoggerController(loggerOptions);
590
565
  }
591
566
 
592
567
  /**
593
568
  * Create a Winston Logger
594
569
  * @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]
570
+ * @param {[Format|string]} [options.formats]
571
+ * @param {[Object|String]} [options.transports]
599
572
  * @returns {winston.Logger}
600
573
  */
601
574
  #createWinstonLogger = (options) => {
602
575
  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));
576
+ const format = this.#buildWinstonFormat(options, options.formats);
577
+ const transports = this.#buildWinstonTransports(options.transports);
578
+ return createWinstonLogger({ format, transports });
614
579
  }
615
580
 
616
581
  /**
@@ -633,13 +598,66 @@ class ZeddemoreLogger extends ZeddemoreBase {
633
598
  monkeyPatchConsole(methodNames, colors, depth, showHidden);
634
599
  }
635
600
 
601
+ #formatInfoMutation(options) {
602
+ return winstonFormat((info) => {
603
+ info.id = info.id || options.id || null;
604
+ info.ip = info.ip || options.ip || null;
605
+ info.user = info.user || options.user || null;
606
+ return info;
607
+ });
608
+ }
609
+
610
+ #getBuiltinFormat(format, options) {
611
+ options = options || { };
612
+ switch (format) {
613
+ case wf.COLORIZE: return winstonFormat.colorize();
614
+ case wf.JSON: return winstonFormat.json();
615
+ case wf.METADATA: return winstonFormat.metadata();
616
+ case wf.PRETTY_PRINT: return winstonFormat.prettyPrint();
617
+ case wf.SIMPLE: return winstonFormat.simple();
618
+ case wf.SPLAT: return winstonFormat.splat();
619
+ case wf.TIMESTAMP: return winstonFormat.timestamp();
620
+ case wf.ZEDDEMORE_INFO_MUTATION: return this.#formatInfoMutation(options)();
621
+ case wf.ZEDDEMORE_LABEL: return winstonFormat.label({ label: options.label || this.defaultLabel });
622
+ case wf.ZEDDEMORE_PRINTF: return winstonFormat.printf(this.#buildWinstonTemplate);
623
+ case wf.ZEDDEMORE_TIMESTAMP: return winstonFormat.timestamp({ format: this.winstonTimestampFormat });
624
+ }
625
+ }
626
+
627
+ #getBuiltinTransport(transport) {
628
+ let logLevel = this.logLevel;
629
+ const logLevelType = transportLogLevelType(transport);
630
+ switch (logLevelType) {
631
+ case llt.CONSOLE: logLevel = this.logLevel; break;
632
+ case llt.EMAIL: logLevel = this.emailLogLevel; break;
633
+ }
634
+ switch (transport) {
635
+ case wt.CONSOLE: return this.#buildWinstonConsoleTransport(logLevel);
636
+ case wt.EMAIL: return this.#buildWinstonEmailTransport(logLevel);
637
+ }
638
+ }
639
+
640
+ #getDefaultFormats(options) {
641
+ return _.compact(defaults.winstonFormats.map((format) => this.#getBuiltinFormat(format, options)));
642
+ }
643
+
644
+ #getDefaultTransports() {
645
+ return _.compact(defaults.winstonTransports.map((transport) => {
646
+ switch (transport) {
647
+ case wt.CONSOLE: return this.doConsoleLog ? wt.CONSOLE : null;
648
+ case wt.EMAIL: return (this.doEmailLog && this.canEmailLog) ? wt.EMAIL : null;
649
+ default: return transport;
650
+ }
651
+ }));
652
+ }
653
+
636
654
  /**
637
- * Get a Zeddemore Logger wrapper instance
655
+ * Get a Zeddemore Logger wrapper instance with all transports
638
656
  * @param {Object} options
639
- * @param {[Format]} [options.formats]
657
+ * @param {[Format|String]} [options.formats]
640
658
  * @param {String} [options.level]
641
659
  * @param {ZeddemoreLoggerController} [options.logger]
642
- * @param {[Object]} [options.transports]
660
+ * @param {[Object|String]} [options.transports]
643
661
  * @param {Object} [options.user]
644
662
  * @returns {ZeddemoreLoggerController}
645
663
  */
@@ -647,25 +665,9 @@ class ZeddemoreLogger extends ZeddemoreBase {
647
665
  options = options || { };
648
666
  /** @type {app} app */
649
667
  const logger = options.logger || (options.user ? options.user.logger : null) || ((app && app.locals) ? app.locals.logger : null);
650
- if (!!logger) return logger;
668
+ if (logger instanceof ZeddemoreLoggerController) return logger;
651
669
  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);
670
+ return zeddemoreLogger.createLoggerController(options);
669
671
  }
670
672
 
671
673
  /**
@@ -715,7 +717,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
715
717
  */
716
718
  log = (logLevel) => {
717
719
  logLevel = logLevel || this.logLevel;
718
- const logLevelName = logLevelToWinstonLogLevelName(logLevel);
720
+ const logLevelName = winstonLogLevelName(logLevel);
719
721
  return this.logger[ logLevelName ];
720
722
  }
721
723
 
@@ -776,7 +778,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
776
778
  return `${ packageName }@${ _package.version }`;
777
779
  }
778
780
  const versionParts = _.compact(_.sortBy(packages, (_package) => _package.name.toUpperCase()).map(buildVersionLabel));
779
- this.log(logLevel)(`Packages: ${ versionParts.join(' | ') }`);
781
+ this.log(logLevel)(`Packages: [ ${ versionParts.join(', ') } ]`);
780
782
  }
781
783
 
782
784
  /**
@@ -797,7 +799,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
797
799
  const msgParts = [ `${ routes.length } ${ routesLabel } ${ addedLabel }` ];
798
800
  if (showCategories) {
799
801
  const categories = options.categories || this.apiRouteCategories || [];
800
- msgParts.push(`in: ${ categories.sort().join('/') }`);
802
+ msgParts.push(`in: [ ${ categories.sort().join(', ') } ]`);
801
803
  }
802
804
  this.log(logLevel)(msgParts.join(', '));
803
805
  }
@@ -869,11 +871,12 @@ class ZeddemoreLogger extends ZeddemoreBase {
869
871
  const user = this.userGetFn(req, res);
870
872
  if (user) logOptions.user = user;
871
873
  const response = colorize ? this.#colorizeResponse(message.trim()) : message.trim();
872
- ZeddemoreLogger.getLogger(logOptions).http(response);
873
- if (this.doEmailLog) {
874
+ const logger = ZeddemoreLogger.getLogger(logOptions);
875
+ logger.http(response);
876
+ if (this.doEmailLog && this.canEmailLog) {
874
877
  const statusCode = extractHttpStatusCode(message);
875
878
  if (isResponseFailure(statusCode, [ 404 ])) {
876
- ZeddemoreLogger.getLogger(logOptions).log({ level: wlln.ERROR, message: response, transport: wti.EMAIL });
879
+ logger.logEmail({ level: wlln.ERROR, message: response });
877
880
  }
878
881
  }
879
882
  },
@@ -1024,7 +1027,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
1024
1027
  const _request = axiosResponse.request;
1025
1028
  const axiosConfig = logOptions.axios || { };
1026
1029
  const configData = (logOptions.data && _.isObject(axiosConfig.data)) ? JSON.stringify(axiosConfig.data) : null;
1027
- const logLevel = logLevelToWinstonLogLevelName(logOptions.logLevel);
1030
+ const logLevel = winstonLogLevelName(logOptions.logLevel);
1028
1031
  const logger = options.logger || ZeddemoreLogger.getLogger(options);
1029
1032
  if (!logger) return;
1030
1033
  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
  };