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 +1 -1
- package/lib/ZeddemoreBase.js +4 -4
- package/lib/ZeddemoreLogger.js +123 -117
- package/lib/ZeddemoreLoggerController.js +27 -17
- package/lib/defaults.js +5 -14
- package/lib/enums.js +41 -40
- package/lib/logging.js +37 -25
- package/lib/mappings/color_mappings.js +9 -10
- package/lib/mappings/log_mappings.js +16 -9
- package/lib/zeddemore-logger.js +5 -4
- package/package.json +1 -2
- package/lib/ZeddemoreProgressMultibar.js +0 -776
package/lib/enums.js
CHANGED
|
@@ -22,28 +22,6 @@ const ansiColors = {
|
|
|
22
22
|
LOG_LEVEL_WARNING: 33, // yellow
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const apiLogLevelCaptions = {
|
|
26
|
-
DEFAULT: 'Default',
|
|
27
|
-
ERROR: 'Error',
|
|
28
|
-
WARNING: 'Warning',
|
|
29
|
-
INFO: 'Info',
|
|
30
|
-
HTTP: 'HTTP',
|
|
31
|
-
VERBOSE: 'Verbose',
|
|
32
|
-
DEBUG: 'Debug',
|
|
33
|
-
SILLY: 'Silly',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const apiLogLevels = {
|
|
37
|
-
DEFAULT: -1,
|
|
38
|
-
ERROR: 0,
|
|
39
|
-
WARNING: 1,
|
|
40
|
-
INFO: 2,
|
|
41
|
-
HTTP: 3,
|
|
42
|
-
VERBOSE: 4,
|
|
43
|
-
DEBUG: 5,
|
|
44
|
-
SILLY: 6,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
25
|
const chalkFormats = {
|
|
48
26
|
ANSI: 'ansi',
|
|
49
27
|
HEX: 'hex',
|
|
@@ -55,14 +33,6 @@ const chalkLayers = {
|
|
|
55
33
|
FOREGROUND: 'fg',
|
|
56
34
|
};
|
|
57
35
|
|
|
58
|
-
const databaseOperations = {
|
|
59
|
-
DELETE: 'DELETE',
|
|
60
|
-
INSERT: 'INSERT',
|
|
61
|
-
SELECT: 'SELECT',
|
|
62
|
-
TRUNCATE: 'TRUNCATE',
|
|
63
|
-
UPDATE: 'UPDATE',
|
|
64
|
-
};
|
|
65
|
-
|
|
66
36
|
const hexColors = {
|
|
67
37
|
BEARDON_RED: '#951A1D',
|
|
68
38
|
BLACK: '#000000',
|
|
@@ -81,11 +51,19 @@ const hexColors = {
|
|
|
81
51
|
HTTP_POST: '#F4DA7A',
|
|
82
52
|
HTTP_PUT: '#74AEF6',
|
|
83
53
|
HTTP_TRACE: '#FFFFFF',
|
|
54
|
+
PACKAGE_ANGULARJS: '#C04737',
|
|
55
|
+
PACKAGE_AXIOS: '#6200e1',
|
|
84
56
|
PACKAGE_EXPRESS: '#F7DF1E',
|
|
57
|
+
PACKAGE_HANDLEBARS: '#F0772B',
|
|
58
|
+
PACKAGE_JIMP: '#FF0000',
|
|
85
59
|
PACKAGE_MYSQL: '#00618A',
|
|
86
60
|
PACKAGE_NODE_JS: '#689F63',
|
|
61
|
+
PACKAGE_PASSPORT: '#51E492',
|
|
62
|
+
PACKAGE_PDFKIT: '#DB000D',
|
|
87
63
|
PACKAGE_POSTGRESQL: '#336791',
|
|
64
|
+
PACKAGE_REDIS: '#C23936',
|
|
88
65
|
PACKAGE_SEQUELIZE: '#00AFEF',
|
|
66
|
+
PACKAGE_ZEDDEMORE: '#E2B68F',
|
|
89
67
|
};
|
|
90
68
|
|
|
91
69
|
const httpStatusCodeGroups = {
|
|
@@ -122,6 +100,11 @@ const httpResponseHeaders = {
|
|
|
122
100
|
CONTENT_LENGTH: 'Content-Length',
|
|
123
101
|
};
|
|
124
102
|
|
|
103
|
+
const logLevelTypes = {
|
|
104
|
+
CONSOLE: 'console',
|
|
105
|
+
EMAIL: 'email',
|
|
106
|
+
};
|
|
107
|
+
|
|
125
108
|
const morganFormats = {
|
|
126
109
|
COMBINED: 'combined',
|
|
127
110
|
COMMON: 'common',
|
|
@@ -151,10 +134,18 @@ const morganFormatTokens = {
|
|
|
151
134
|
USER_AGENT: 'user-agent',
|
|
152
135
|
};
|
|
153
136
|
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
137
|
+
const winstonFormats = {
|
|
138
|
+
COLORIZE: 'colorize',
|
|
139
|
+
JSON: 'json',
|
|
140
|
+
METADATA: 'metadata',
|
|
141
|
+
PRETTY_PRINT: 'pretty_print',
|
|
142
|
+
SIMPLE: 'simple',
|
|
143
|
+
SPLAT: 'splat',
|
|
144
|
+
TIMESTAMP: 'timestamp',
|
|
145
|
+
ZEDDEMORE_INFO_MUTATION: 'zeddemore_info_mutation',
|
|
146
|
+
ZEDDEMORE_LABEL: 'zeddemore_label',
|
|
147
|
+
ZEDDEMORE_PRINTF: 'zeddemore_printf',
|
|
148
|
+
ZEDDEMORE_TIMESTAMP: 'zeddemore_timestamp',
|
|
158
149
|
};
|
|
159
150
|
|
|
160
151
|
const winstonLogLevelNames = {
|
|
@@ -178,28 +169,38 @@ const winstonLogLevels = {
|
|
|
178
169
|
SILLY: 6,
|
|
179
170
|
};
|
|
180
171
|
|
|
181
|
-
const
|
|
172
|
+
const winstonTransports = {
|
|
182
173
|
CONSOLE: 'console',
|
|
183
174
|
EMAIL: 'email',
|
|
184
175
|
};
|
|
185
176
|
|
|
177
|
+
const zeddemoreLogLevelCaptions = {
|
|
178
|
+
DEFAULT: 'Default',
|
|
179
|
+
ERROR: 'Error',
|
|
180
|
+
WARNING: 'Warning',
|
|
181
|
+
INFO: 'Info',
|
|
182
|
+
HTTP: 'HTTP',
|
|
183
|
+
VERBOSE: 'Verbose',
|
|
184
|
+
DEBUG: 'Debug',
|
|
185
|
+
SILLY: 'Silly',
|
|
186
|
+
};
|
|
187
|
+
|
|
186
188
|
module.exports = {
|
|
187
189
|
doesEnumInclude,
|
|
188
190
|
ansiColors,
|
|
189
|
-
apiLogLevelCaptions,
|
|
190
|
-
apiLogLevels,
|
|
191
191
|
chalkFormats,
|
|
192
192
|
chalkLayers,
|
|
193
|
-
databaseOperations,
|
|
194
193
|
hexColors,
|
|
195
194
|
httpStatusCodeGroups,
|
|
196
195
|
httpMethods,
|
|
197
196
|
httpRequestHeaders,
|
|
198
197
|
httpResponseHeaders,
|
|
198
|
+
logLevelTypes,
|
|
199
199
|
morganFormats,
|
|
200
200
|
morganFormatTokens,
|
|
201
|
-
|
|
201
|
+
winstonFormats,
|
|
202
202
|
winstonLogLevelNames,
|
|
203
203
|
winstonLogLevels,
|
|
204
|
-
|
|
204
|
+
winstonTransports,
|
|
205
|
+
zeddemoreLogLevelCaptions,
|
|
205
206
|
};
|
package/lib/logging.js
CHANGED
|
@@ -4,7 +4,7 @@ const _ = require('lodash');
|
|
|
4
4
|
|
|
5
5
|
const defaults = require('./defaults');
|
|
6
6
|
const enums = require('./enums');
|
|
7
|
-
const { logLevelMap } = require('./mappings/log_mappings');
|
|
7
|
+
const { logLevelMap, transportMap } = require('./mappings/log_mappings');
|
|
8
8
|
|
|
9
9
|
const { doesEnumInclude } = enums;
|
|
10
10
|
|
|
@@ -12,47 +12,57 @@ function isMorganFormat(format) {
|
|
|
12
12
|
return doesEnumInclude(enums.morganFormats, format);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function isWinstonFormat(format) {
|
|
16
|
+
return doesEnumInclude(enums.winstonFormats, format);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isWinstonLogLevel(level) {
|
|
20
|
+
if (!_.isInteger(level) && (!_.isString(level) || !level.length)) return false;
|
|
21
|
+
if (_.isInteger(level)) return isWinstonLogLevelId(level);
|
|
22
|
+
if (_.isString(level)) return isWinstonLogLevelName(level);
|
|
19
23
|
return false;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
function
|
|
23
|
-
if (!_.isInteger(
|
|
24
|
-
return !!(_.find(logLevelMap, { winstonLevel:
|
|
26
|
+
function isWinstonLogLevelId(id) {
|
|
27
|
+
if (!_.isInteger(id)) return false;
|
|
28
|
+
return !!(_.find(logLevelMap, { winstonLevel: id }))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isWinstonLogLevelName(name) {
|
|
32
|
+
if (!_.isString(name)) return false;
|
|
33
|
+
return !!(_.find(logLevelMap, { winstonName: name }))
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
return !!(_.find(logLevelMap, { winstonName: logLevelName }))
|
|
36
|
+
function isWinstonTransport(winstonTransport) {
|
|
37
|
+
return doesEnumInclude(enums.winstonTransports, winstonTransport);
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
function
|
|
33
|
-
return
|
|
40
|
+
function transportLogLevelType(transport) {
|
|
41
|
+
if (!isWinstonTransport(transport)) return defaults.logLevelType;
|
|
42
|
+
const transportEntry = _.find(transportMap, { transport });
|
|
43
|
+
return (transportEntry ? transportEntry.type : null) || defaults.logLevelType;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
/**
|
|
37
|
-
* Convert a log level ID to a
|
|
47
|
+
* Convert a Winston log level ID to a name
|
|
38
48
|
* @param levelId {number}
|
|
39
49
|
* @returns {string}
|
|
40
50
|
*/
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
51
|
+
function winstonLogLevelIdName(levelId) {
|
|
52
|
+
if (!isWinstonLogLevelId(levelId)) return defaults.winstonLogLevelName;
|
|
43
53
|
const logLevelEntry = _.find(logLevelMap, { winstonLevel: levelId });
|
|
44
54
|
return (logLevelEntry ? logLevelEntry.winstonName : null) || defaults.winstonLogLevelName;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
/**
|
|
48
|
-
* Convert a log level to a
|
|
58
|
+
* Convert a Winston log level to a name
|
|
49
59
|
* @param logLevel {number|string}
|
|
50
60
|
* @returns {string}
|
|
51
61
|
*/
|
|
52
|
-
function
|
|
53
|
-
if (!
|
|
62
|
+
function winstonLogLevelName(logLevel) {
|
|
63
|
+
if (!isWinstonLogLevel(logLevel)) return defaults.winstonLogLevelName;
|
|
54
64
|
if (_.isString(logLevel)) return logLevel;
|
|
55
|
-
return
|
|
65
|
+
return winstonLogLevelIdName(logLevel);
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
/**
|
|
@@ -73,10 +83,12 @@ function monkeyPatchConsole(methodNames = [ defaults.consoleDirExtensionMethodNa
|
|
|
73
83
|
|
|
74
84
|
module.exports = {
|
|
75
85
|
isMorganFormat,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
logLevelToWinstonLogLevelName,
|
|
86
|
+
isWinstonFormat,
|
|
87
|
+
isWinstonLogLevel,
|
|
88
|
+
isWinstonLogLevelId,
|
|
89
|
+
isWinstonTransport,
|
|
81
90
|
monkeyPatchConsole,
|
|
91
|
+
transportLogLevelType,
|
|
92
|
+
winstonLogLevelIdName,
|
|
93
|
+
winstonLogLevelName,
|
|
82
94
|
};
|
|
@@ -3,15 +3,7 @@
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const enums = require('../enums');
|
|
5
5
|
|
|
6
|
-
const { ansiColors: ac,
|
|
7
|
-
|
|
8
|
-
const databaseOperationColors = [
|
|
9
|
-
{ match: dbo.DELETE, style: { format: cf.HEX, fore: hc.DB_DELETE, back: null } },
|
|
10
|
-
{ match: dbo.INSERT, style: { format: cf.HEX, fore: hc.DB_INSERT, back: null } },
|
|
11
|
-
{ match: dbo.SELECT, style: { format: cf.HEX, fore: hc.DB_SELECT, back: null } },
|
|
12
|
-
{ match: dbo.TRUNCATE, style: { format: cf.HEX, fore: hc.DB_TRUNCATE, back: null } },
|
|
13
|
-
{ match: dbo.UPDATE, style: { format: cf.HEX, fore: hc.DB_UPDATE, back: null } },
|
|
14
|
-
];
|
|
6
|
+
const { ansiColors: ac, chalkFormats: cf, hexColors: hc, httpMethods: http, winstonLogLevelNames: wlln } = enums;
|
|
15
7
|
|
|
16
8
|
const httpStatusColors = [
|
|
17
9
|
{ range: _.range(500, 600), style: { format: cf.ANSI, fore: ac.HTTP_SERVER_ERROR, back: null } },
|
|
@@ -44,15 +36,22 @@ const logLevelColors = [
|
|
|
44
36
|
];
|
|
45
37
|
|
|
46
38
|
const packageColors = [
|
|
39
|
+
{ match: 'AngularJS', style: { format: cf.HEX, fore: hc.PACKAGE_ANGULARJS, back: null } },
|
|
40
|
+
{ match: 'Axios', style: { format: cf.HEX, fore: hc.PACKAGE_AXIOS, back: null } },
|
|
47
41
|
{ match: 'express', style: { format: cf.HEX, fore: hc.PACKAGE_EXPRESS, back: null } },
|
|
42
|
+
{ match: 'Handlebars', style: { format: cf.HEX, fore: hc.PACKAGE_HANDLEBARS, back: null } },
|
|
43
|
+
{ match: 'Jimp', style: { format: cf.HEX, fore: hc.PACKAGE_JIMP, back: null } },
|
|
48
44
|
{ match: 'MySQL', style: { format: cf.HEX, fore: hc.PACKAGE_MYSQL, back: null } },
|
|
49
45
|
{ match: 'Node.js', style: { format: cf.HEX, fore: hc.PACKAGE_NODE_JS, back: null } },
|
|
46
|
+
{ match: 'passport', style: { format: cf.HEX, fore: hc.PACKAGE_PASSPORT, back: null } },
|
|
47
|
+
{ match: 'PDFKit', style: { format: cf.HEX, fore: hc.PACKAGE_PDFKIT, back: null } },
|
|
50
48
|
{ match: 'PostgreSQL', style: { format: cf.HEX, fore: hc.PACKAGE_POSTGRESQL, back: null } },
|
|
49
|
+
{ match: 'Redis', style: { format: cf.HEX, fore: hc.PACKAGE_REDIS, back: null } },
|
|
51
50
|
{ match: 'sequelize', style: { format: cf.HEX, fore: hc.PACKAGE_SEQUELIZE, back: null } },
|
|
51
|
+
{ match: 'Zeddemore', style: { format: cf.HEX, fore: hc.PACKAGE_ZEDDEMORE, back: null } },
|
|
52
52
|
];
|
|
53
53
|
|
|
54
54
|
module.exports = {
|
|
55
|
-
databaseOperationColors,
|
|
56
55
|
httpStatusColors,
|
|
57
56
|
httpVerbColors,
|
|
58
57
|
logLevelColors,
|
|
@@ -2,19 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
const enums = require('../enums');
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { logLevelTypes: llt, winstonLogLevelNames: wlln, winstonLogLevels: wll, winstonTransports: wt,
|
|
6
|
+
zeddemoreLogLevelCaptions: zllc } = enums;
|
|
6
7
|
|
|
7
8
|
const logLevelMap = [
|
|
8
|
-
{
|
|
9
|
-
{
|
|
10
|
-
{
|
|
11
|
-
{
|
|
12
|
-
{
|
|
13
|
-
{
|
|
14
|
-
{
|
|
15
|
-
{
|
|
9
|
+
{ winstonLevel: null, winstonName: null, caption: zllc.DEFAULT },
|
|
10
|
+
{ winstonLevel: wll.ERROR, winstonName: wlln.ERROR, caption: zllc.ERROR },
|
|
11
|
+
{ winstonLevel: wll.WARNING, winstonName: wlln.WARNING, caption: zllc.WARNING },
|
|
12
|
+
{ winstonLevel: wll.INFO, winstonName: wlln.INFO, caption: zllc.INFO },
|
|
13
|
+
{ winstonLevel: wll.HTTP, winstonName: wlln.HTTP, caption: zllc.HTTP },
|
|
14
|
+
{ winstonLevel: wll.VERBOSE, winstonName: wlln.VERBOSE, caption: zllc.VERBOSE },
|
|
15
|
+
{ winstonLevel: wll.DEBUG, winstonName: wlln.DEBUG, caption: zllc.DEBUG },
|
|
16
|
+
{ winstonLevel: wll.SILLY, winstonName: wlln.SILLY, caption: zllc.SILLY },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const transportMap = [
|
|
20
|
+
{ transport: wt.CONSOLE, type: llt.CONSOLE },
|
|
21
|
+
{ transport: wt.EMAIL, type: llt.EMAIL },
|
|
16
22
|
];
|
|
17
23
|
|
|
18
24
|
module.exports = {
|
|
19
25
|
logLevelMap,
|
|
26
|
+
transportMap,
|
|
20
27
|
};
|
package/lib/zeddemore-logger.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
// Copyright (c) 2025 by Beardon Services, Inc.
|
|
1
|
+
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { winstonLogLevelIdName } = require('./logging');
|
|
4
4
|
const ZeddemoreLogger = require('./ZeddemoreLogger');
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
enums: require('./enums'),
|
|
8
8
|
log: ZeddemoreLogger.getLogger,
|
|
9
|
-
logLevelIdToWinstonLogLevelName,
|
|
10
|
-
|
|
9
|
+
logLevelIdToWinstonLogLevelName: winstonLogLevelIdName, // deprecated naming
|
|
10
|
+
winstonLogLevelIdName,
|
|
11
|
+
winstonLogLevelIdToName: winstonLogLevelIdName, // deprecated naming
|
|
11
12
|
writeAxiosErrorLog: ZeddemoreLogger.writeAxiosErrorLog,
|
|
12
13
|
writeAxiosLog: ZeddemoreLogger.writeAxiosResponseLog, // deprecated
|
|
13
14
|
writeAxiosResponseLog: ZeddemoreLogger.writeAxiosResponseLog,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zeddemore-logger",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Node.js Express logger using Morgan and Winston for thread and caller info tracking",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"ansi-html": "^0.0.9",
|
|
24
24
|
"chalk": "^4.1.2",
|
|
25
|
-
"cli-progress": "^3.12.0",
|
|
26
25
|
"lodash": "^4.18.1",
|
|
27
26
|
"luxon": "^3.7.1",
|
|
28
27
|
"morgan": "^1.10.1",
|