zeddemore-logger 1.2.4 → 2.0.0
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 +1 -1
- package/lib/ZeddemoreBase.js +283 -0
- package/lib/ZeddemoreLogger.js +814 -0
- package/lib/ZeddemoreLoggerController.js +72 -0
- package/lib/ZeddemoreProgressMultibar.js +776 -0
- package/lib/date.js +24 -1
- package/lib/defaults.js +37 -0
- package/lib/enums.js +15 -0
- package/lib/logging.js +76 -0
- package/lib/typedef.js +33 -0
- package/lib/uuid.js +11 -0
- package/lib/zeddemore-logger.js +5 -579
- package/package.json +4 -2
package/lib/date.js
CHANGED
|
@@ -2,9 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
|
|
5
|
+
function convertFechaDateFormatToLuxon(dateFormat) {
|
|
6
|
+
const tokenMappings = [
|
|
7
|
+
{ fecha: 'YYYY', luxon: 'yyyy' },
|
|
8
|
+
{ fecha: 'YY', luxon: 'yy' },
|
|
9
|
+
{ fecha: 'MMMM', luxon: 'LLLL' },
|
|
10
|
+
{ fecha: 'MMM', luxon: 'LLL' },
|
|
11
|
+
{ fecha: 'MM', luxon: 'LL' },
|
|
12
|
+
{ fecha: 'M', luxon: 'L' },
|
|
13
|
+
{ fecha: 'dddd', luxon: 'cccc' },
|
|
14
|
+
{ fecha: 'ddd', luxon: 'ccc' },
|
|
15
|
+
{ fecha: 'DD', luxon: 'dd' },
|
|
16
|
+
{ fecha: 'D', luxon: 'd' },
|
|
17
|
+
{ fecha: 'SS', luxon: 'SSS' },
|
|
18
|
+
];
|
|
19
|
+
if (!_.isString(dateFormat)) return null;
|
|
20
|
+
let _dateFormat = dateFormat.trim();
|
|
21
|
+
for (const tokenMapping of tokenMappings) {
|
|
22
|
+
_dateFormat = _dateFormat.replaceAll(tokenMapping.fecha, tokenMapping.luxon);
|
|
23
|
+
}
|
|
24
|
+
return _dateFormat;
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
function convertMilliseconds(milliseconds, options) {
|
|
6
28
|
options = options || { };
|
|
7
|
-
const digits = _.isInteger(options.digits) ? options.digits :
|
|
29
|
+
const digits = _.isInteger(options.digits) ? options.digits : 2;
|
|
8
30
|
const spaced = _.isBoolean(options.spaced) ? options.spaced : false;
|
|
9
31
|
let value = milliseconds || 0;
|
|
10
32
|
let unit = 'ms';
|
|
@@ -49,5 +71,6 @@ function convertMilliseconds(milliseconds, options) {
|
|
|
49
71
|
}
|
|
50
72
|
|
|
51
73
|
module.exports = {
|
|
74
|
+
convertFechaDateFormatToLuxon,
|
|
52
75
|
convertMilliseconds,
|
|
53
76
|
};
|
package/lib/defaults.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (c) 2024-2025 by Beardon Services, Inc.
|
|
2
|
+
|
|
3
|
+
const enums = require('./enums');
|
|
4
|
+
|
|
5
|
+
const { hexColors: hc, morganFormats: mf, morganFormatTokens: mft, winstonLogLevelNames: wlln } = enums;
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
colorConsoleWhiteHex: hc.CONSOLE_WHITE,
|
|
9
|
+
consoleDirExtensionMethodName: 'dirp',
|
|
10
|
+
consoleDirExtensionColors: true,
|
|
11
|
+
consoleDirExtensionDepth: null,
|
|
12
|
+
consoleDirExtensionShowHidden: true,
|
|
13
|
+
consoleTransportName: 'console',
|
|
14
|
+
contentLengthDigits: 2,
|
|
15
|
+
liveMessage: '⚡live⚡',
|
|
16
|
+
morganFormat: mf.ZEDDEMORE,
|
|
17
|
+
morganFormatTokens: [ mft.METHOD, mft.DECODED_URL, mft.STATUS, mft.RESPONSE_TIME_FORMAT, mft.CONTENT_LENGTH_FORMAT ],
|
|
18
|
+
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
|
+
requestIdAttribute: 'requestId',
|
|
32
|
+
requestIdIcon: '🧵',
|
|
33
|
+
responseTimeDigits: 0,
|
|
34
|
+
timestampFormat: 'YYYY-MM-DD HH:mm:ss',
|
|
35
|
+
userLogLevel: -1,
|
|
36
|
+
winstonLogLevelName: wlln.INFO,
|
|
37
|
+
};
|
package/lib/enums.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// Copyright (c) 2025 by Beardon Services, Inc.
|
|
2
2
|
|
|
3
|
+
function doesEnumInclude(set, value) {
|
|
4
|
+
for (const key in set) {
|
|
5
|
+
if (set[ key ] === value) return true;
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
const ansiColors = {
|
|
4
11
|
HTTP_CLIENT_ERROR: 33, // red
|
|
5
12
|
HTTP_INFORMATIONAL: 0, // white
|
|
@@ -144,6 +151,12 @@ const morganFormatTokens = {
|
|
|
144
151
|
USER_AGENT: 'user-agent',
|
|
145
152
|
};
|
|
146
153
|
|
|
154
|
+
const progressBarAlignments = {
|
|
155
|
+
CENTER: 'center',
|
|
156
|
+
LEFT: 'left',
|
|
157
|
+
RIGHT: 'right',
|
|
158
|
+
};
|
|
159
|
+
|
|
147
160
|
const winstonLogLevelNames = {
|
|
148
161
|
ERROR: 'error',
|
|
149
162
|
WARNING: 'warn',
|
|
@@ -166,6 +179,7 @@ const winstonLogLevels = {
|
|
|
166
179
|
};
|
|
167
180
|
|
|
168
181
|
module.exports = {
|
|
182
|
+
doesEnumInclude,
|
|
169
183
|
ansiColors,
|
|
170
184
|
apiLogLevelCaptions,
|
|
171
185
|
apiLogLevels,
|
|
@@ -179,6 +193,7 @@ module.exports = {
|
|
|
179
193
|
httpResponseHeaders,
|
|
180
194
|
morganFormats,
|
|
181
195
|
morganFormatTokens,
|
|
196
|
+
progressBarAlignments,
|
|
182
197
|
winstonLogLevelNames,
|
|
183
198
|
winstonLogLevels,
|
|
184
199
|
};
|
package/lib/logging.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright (c) 2025 by Beardon Services, Inc.
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
const defaults = require('./defaults');
|
|
6
|
+
const enums = require('./enums');
|
|
7
|
+
const { logLevelMap } = require('./mappings/log_mappings');
|
|
8
|
+
|
|
9
|
+
const { doesEnumInclude } = enums;
|
|
10
|
+
|
|
11
|
+
function isMorganFormat(format) {
|
|
12
|
+
return doesEnumInclude(enums.morganFormats, format);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isValidLogLevel(logLevel) {
|
|
16
|
+
if (!logLevel) return false;
|
|
17
|
+
if (_.isInteger(logLevel)) return isValidLogLevelId(logLevel);
|
|
18
|
+
if (_.isString(logLevel)) return isValidLogLevelName(logLevel);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isValidLogLevelId(logLevelId) {
|
|
23
|
+
if (!_.isInteger(logLevelId)) return false;
|
|
24
|
+
return !!(_.find(logLevelMap, { winstonLevel: logLevelId }))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isValidLogLevelName(logLevelName) {
|
|
28
|
+
if (!_.isString(logLevelName)) return false;
|
|
29
|
+
return !!(_.find(logLevelMap, { winstonName: logLevelName }))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Convert a log level ID to a Winston log level name
|
|
34
|
+
* @param levelId {number}
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
function logLevelIdToWinstonLogLevelName(levelId) {
|
|
38
|
+
if (!isValidLogLevelId(levelId)) return defaults.winstonLogLevelName;
|
|
39
|
+
const logLevelEntry = _.find(logLevelMap, { winstonLevel: levelId });
|
|
40
|
+
return (logLevelEntry ? logLevelEntry.winstonName : null) || defaults.winstonLogLevelName;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Convert a log level to a Winston log level name
|
|
45
|
+
* @param logLevel {number|string}
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
function logLevelToWinstonLogLevelName(logLevel) {
|
|
49
|
+
if (!isValidLogLevel(logLevel)) return defaults.winstonLogLevelName;
|
|
50
|
+
if (_.isString(logLevel)) return logLevel;
|
|
51
|
+
return logLevelIdToWinstonLogLevelName(logLevel);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Monkey patch console to allow unlimited depth with `console.dirp`
|
|
56
|
+
*/
|
|
57
|
+
function monkeyPatchConsole(methodNames = [ defaults.consoleDirExtensionMethodName ], colors = defaults.consoleDirExtensionColors, depth = defaults.consoleDirExtensionDepth, showHidden = defaults.consoleDirExtensionShowHidden) {
|
|
58
|
+
if (!_.isArray(methodNames)) methodNames = [ methodNames ];
|
|
59
|
+
const _colors = _.isBoolean(colors) ? colors : defaults.consoleDirExtensionColors;
|
|
60
|
+
const _depth = _.isInteger(depth) ? depth : defaults.consoleDirExtensionDepth;
|
|
61
|
+
const _showHidden = _.isBoolean(showHidden) ? showHidden : defaults.consoleDirExtensionShowHidden;
|
|
62
|
+
for (const methodName of methodNames) {
|
|
63
|
+
if (!!console[ methodName ]) continue;
|
|
64
|
+
console[ methodName ] = function(...args) {
|
|
65
|
+
console.dir(args, { colors: _colors, depth: _depth, showHidden: _showHidden });
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
isMorganFormat,
|
|
72
|
+
isValidLogLevel,
|
|
73
|
+
logLevelIdToWinstonLogLevelName,
|
|
74
|
+
logLevelToWinstonLogLevelName,
|
|
75
|
+
monkeyPatchConsole,
|
|
76
|
+
};
|
package/lib/typedef.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @typedef {Object} app
|
|
2
|
+
* @property {Object} locals
|
|
3
|
+
* @property {ZeddemoreLoggerController|null} locals.logger
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object|null} Metadata
|
|
8
|
+
* @property {String} [caller]
|
|
9
|
+
* @property {String} [fullId]
|
|
10
|
+
* @property {String} [id]
|
|
11
|
+
* @property {String} [ip]
|
|
12
|
+
* @property {String} [label]
|
|
13
|
+
* @property {String} [prefix]
|
|
14
|
+
* @property {Boolean} [raw]
|
|
15
|
+
* @property {String} [subId]
|
|
16
|
+
* @property {String} [target]
|
|
17
|
+
* @property {String} [timestamp]
|
|
18
|
+
* @property {String} [user]
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object|null} SequelizeModel
|
|
23
|
+
* @property {Function} [create]
|
|
24
|
+
* @property {Function} [findOne]
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} user
|
|
29
|
+
* @property {String} [ipAddress]
|
|
30
|
+
* @property {String} [login]
|
|
31
|
+
* @property {number|String} [logLevel]
|
|
32
|
+
* @property {String} [username]
|
|
33
|
+
*/
|