zeddemore-logger 2.2.11 → 2.3.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 +1 -0
- package/lib/ZeddemoreLogger.js +58 -19
- package/lib/color.js +23 -2
- package/lib/date.js +24 -1
- package/lib/enums.js +42 -0
- package/lib/mappings/color_mappings.js +21 -1
- package/lib/mappings/ldap_mappings.js +22 -0
- package/lib/mappings/log_mappings.js +1 -1
- package/lib/math.js +12 -4
- package/lib/zeddemore-logger.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
package/lib/ZeddemoreBase.js
CHANGED
|
@@ -286,6 +286,7 @@ class ZeddemoreBase {
|
|
|
286
286
|
fullId: `${ defaults.requestIdIcon }${ id }${ (subId ? `[${ subId }]` : '') }`,
|
|
287
287
|
id,
|
|
288
288
|
ip: metadata.ip || null,
|
|
289
|
+
isLdap: _.isBoolean(metadata.ldap) ? metadata.ldap : false,
|
|
289
290
|
label: target || label || this.defaultLabel,
|
|
290
291
|
originalLabel: label,
|
|
291
292
|
prefix: metadata.prefix || null,
|
package/lib/ZeddemoreLogger.js
CHANGED
|
@@ -4,13 +4,13 @@ const _ = require('lodash');
|
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
const { hostname } = require('node:os');
|
|
6
6
|
const morgan = require('morgan');
|
|
7
|
-
const sizeof = require('object-sizeof');
|
|
8
7
|
const winston = require('winston');
|
|
9
8
|
|
|
10
9
|
const { areHeadersSent, isResponseFailure, isResponseSuccessful } = require('./response');
|
|
11
|
-
const { chalkHttpStatuses, chalkHttpVerbs, chalkLogLevel, chalkPackage,
|
|
12
|
-
|
|
13
|
-
const {
|
|
10
|
+
const { chalkHttpStatuses, chalkHttpVerbs, chalkLdapOperation, chalkLdapStatuses, chalkLogLevel, chalkPackage,
|
|
11
|
+
chalkTarget, stripChalk } = require('./color');
|
|
12
|
+
const { convertBytes, objectBytes } = require('./math');
|
|
13
|
+
const { convertMilliseconds, durationConverted } = require('./date');
|
|
14
14
|
const defaults = require('./defaults');
|
|
15
15
|
const enums = require('./enums');
|
|
16
16
|
const { extractHttpStatusCode, extractHttpVerb } = require('./http');
|
|
@@ -18,14 +18,16 @@ const { extractToken, getRequestResponseTime, isRequestOfMethod, parseRequest }
|
|
|
18
18
|
const { generateUuid } = require('./uuid');
|
|
19
19
|
const { isMorganFormat, isWinstonFormat, isWinstonLogLevelId, isWinstonTransport, monkeyPatchConsole, transportLogLevelType,
|
|
20
20
|
winstonLogLevelName } = require('./logging');
|
|
21
|
+
const { ldapRequestOperationMap } = require('./mappings/ldap_mappings');
|
|
21
22
|
require('./typedef');
|
|
22
23
|
const WinstonEmailTransport = require('./transports/WinstonEmailTransport');
|
|
23
24
|
const ZeddemoreBase = require('./ZeddemoreBase');
|
|
24
25
|
const ZeddemoreLoggerController = require('./ZeddemoreLoggerController');
|
|
25
26
|
|
|
26
27
|
const { createLogger: createWinstonLogger, format: winstonFormat, Logform: Format, transports } = winston;
|
|
27
|
-
const { httpMethods: http, httpRequestHeaders: rqh, httpResponseHeaders: rsh, logLevelTypes: llt,
|
|
28
|
-
morganFormatTokens: mft, winstonFormats: wf, winstonLogLevelNames: wlln, winstonLogLevels: wll,
|
|
28
|
+
const { hexColors: hc, httpMethods: http, httpRequestHeaders: rqh, httpResponseHeaders: rsh, logLevelTypes: llt,
|
|
29
|
+
morganFormats: mf, morganFormatTokens: mft, winstonFormats: wf, winstonLogLevelNames: wlln, winstonLogLevels: wll,
|
|
30
|
+
winstonTransports: wt } = enums;
|
|
29
31
|
|
|
30
32
|
class ZeddemoreLogger extends ZeddemoreBase {
|
|
31
33
|
|
|
@@ -368,19 +370,20 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
368
370
|
|
|
369
371
|
/**
|
|
370
372
|
* Build log message
|
|
371
|
-
* @param {
|
|
372
|
-
* @param {String} [level]
|
|
373
|
-
* @param {String} [error]
|
|
374
|
-
* @param {Metadata} [metadata]
|
|
373
|
+
* @param {Object} info
|
|
375
374
|
* @param {Boolean} [colorize]
|
|
376
375
|
* @returns {string}
|
|
377
376
|
*/
|
|
378
|
-
#buildLogMessage = (
|
|
379
|
-
|
|
377
|
+
#buildLogMessage = (info, colorize = this.colorize) => {
|
|
378
|
+
info = info || { };
|
|
379
|
+
const error = info.err;
|
|
380
|
+
const message = info.message;
|
|
381
|
+
const metadata = this._structureMetadata(info.metadata);
|
|
382
|
+
const level = metadata.isLdap ? info.level.replace(stripChalk(info.level), wlln.LDAP) : info.level;
|
|
380
383
|
const isError = !!level && (level.indexOf(wlln.ERROR) > -1);
|
|
381
384
|
const leaveUncompressed = isError || !!metadata.raw;
|
|
382
385
|
const parts = [ this._buildLogMessagePrefix(level, metadata, colorize) ];
|
|
383
|
-
let msg =
|
|
386
|
+
let msg = _.isArray(message) ? message.join('\n') : message;
|
|
384
387
|
msg = _.isObject(message) ? JSON.stringify(msg) : msg;
|
|
385
388
|
parts.push(leaveUncompressed ? msg : msg.replace(/(\n?\s+)/g, ' '));
|
|
386
389
|
if (!!error) parts.push(error);
|
|
@@ -449,7 +452,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
449
452
|
*/
|
|
450
453
|
#buildWinstonTemplate = (info, colorize = this.colorize) => {
|
|
451
454
|
info = info || { };
|
|
452
|
-
return this.#buildLogMessage(info
|
|
455
|
+
return this.#buildLogMessage(info, colorize);
|
|
453
456
|
}
|
|
454
457
|
|
|
455
458
|
/**
|
|
@@ -769,7 +772,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
769
772
|
if (serverEnvironment) serverParts.push(serverEnvironment);
|
|
770
773
|
if (serverInstance) serverParts.push(serverInstance);
|
|
771
774
|
msgParts.push(`[${ serverParts.join(':') }]`);
|
|
772
|
-
msgParts.push(`Node.js
|
|
775
|
+
msgParts.push(`Node.js server listening on ${ serverHost }:${ chalk.bold(serverPort) }`);
|
|
773
776
|
msgParts.push(`(${ ipVs })`);
|
|
774
777
|
this.log(logLevel)(msgParts.join(' '));
|
|
775
778
|
}
|
|
@@ -1021,8 +1024,9 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
1021
1024
|
const _duration = axiosError.duration || _response.duration;
|
|
1022
1025
|
const duration = _duration ? convertMilliseconds(_duration, logger.responseTimeDigits) : '-';
|
|
1023
1026
|
let _contentLength = _headers ? _headers[ rsh.CONTENT_LENGTH ] : null;
|
|
1024
|
-
if (!_contentLength) _contentLength = _data ?
|
|
1025
|
-
const
|
|
1027
|
+
if (!_contentLength) _contentLength = _data ? objectBytes(_data) : null;
|
|
1028
|
+
const contentLengthDigits = logOptions.contentLengthDigits || logger.contentLengthDigits || defaults.contentLengthDigits;
|
|
1029
|
+
const contentLength = _contentLength ? `- ${ convertBytes(_contentLength, { digits: contentLengthDigits }) }` : null;
|
|
1026
1030
|
const data = _data ? JSON.stringify(_data) : null;
|
|
1027
1031
|
const parts = [ prefix, method, path, status, duration, contentLength, data ];
|
|
1028
1032
|
const message = _.compact(parts).join(' ');
|
|
@@ -1050,14 +1054,49 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
1050
1054
|
const _duration = axiosResponse.duration;
|
|
1051
1055
|
const duration = _duration ? convertMilliseconds(_duration, logger.responseTimeDigits) : '-';
|
|
1052
1056
|
let _contentLength = _headers ? _headers[ rsh.CONTENT_LENGTH ] : null;
|
|
1053
|
-
if (!_contentLength) _contentLength = _data ?
|
|
1057
|
+
if (!_contentLength) _contentLength = _data ? objectBytes(_data) : null;
|
|
1054
1058
|
const contentLengthDigits = logOptions.contentLengthDigits || logger.contentLengthDigits || defaults.contentLengthDigits;
|
|
1055
|
-
const contentLength = _contentLength ? `- ${ convertBytes(_contentLength, contentLengthDigits) }` : null;
|
|
1059
|
+
const contentLength = _contentLength ? `- ${ convertBytes(_contentLength, { digits: contentLengthDigits }) }` : null;
|
|
1056
1060
|
const parts = [ prefix, method, path, configData, status, responseData, duration, contentLength ];
|
|
1057
1061
|
const message = _.compact(parts).join(' ');
|
|
1058
1062
|
logger[ logLevel ](message);
|
|
1059
1063
|
}
|
|
1060
1064
|
|
|
1065
|
+
static writeLdapResponseLog(ldapResponse, logOptions, options) {
|
|
1066
|
+
logOptions = logOptions || { };
|
|
1067
|
+
options = options || { };
|
|
1068
|
+
if (!_.isObject(ldapResponse) || !_.isObject(ldapResponse.req)) return;
|
|
1069
|
+
const _request = ldapResponse.req;
|
|
1070
|
+
const _response = ldapResponse.res || { };
|
|
1071
|
+
const _logLevel = isWinstonLogLevelId(logOptions.logLevel) ? logOptions.logLevel : wll.HTTP;
|
|
1072
|
+
const logLevel = winstonLogLevelName(_logLevel);
|
|
1073
|
+
const logger = options.logger || ZeddemoreLogger.getLogger(options);
|
|
1074
|
+
if (!_.isObject(logger)) return;
|
|
1075
|
+
const _content = ldapResponse.content || null;
|
|
1076
|
+
const _contentLength = objectBytes(_content);
|
|
1077
|
+
const _dn = ldapResponse.dn || ((_.isObject(_request.dn) || _.isString(_request.dn)) ? _request.dn.toString() : null);
|
|
1078
|
+
const _filter = ldapResponse.filter || (_.isObject(_request.filter) ? _request.filter.toString() : null);;
|
|
1079
|
+
const _statusCode = _response.status || _response.code || 0;
|
|
1080
|
+
const isError = (_statusCode > 0);
|
|
1081
|
+
const _requestType = _request.type;
|
|
1082
|
+
const requestOperationEntry = _.find(ldapRequestOperationMap, { type: _requestType });
|
|
1083
|
+
const _operation = ldapResponse.operation || (_.isObject(requestOperationEntry) ? requestOperationEntry.operation : null);
|
|
1084
|
+
const _status = isError ? _response.name : 'OK';
|
|
1085
|
+
const _startTime = _request.startTime;
|
|
1086
|
+
const prefix = logOptions.prefix ? `[${ logOptions.prefix }]` : null;
|
|
1087
|
+
const operation = _.isString(_operation) ? chalkLdapOperation(_operation) : null;
|
|
1088
|
+
const dn = _.isString(_dn) ? chalk.bold(_dn) : null;
|
|
1089
|
+
const filter = _.isString(_filter) ? chalk.hex(hc.LIGHT_GRAY)(_filter) : null;
|
|
1090
|
+
const statusCode = _.isInteger(_statusCode) ? chalkLdapStatuses(_statusCode) : null;
|
|
1091
|
+
const status = _.isInteger(_statusCode) ? chalkLdapStatuses(_statusCode, _status) : null;
|
|
1092
|
+
const responseTime = durationConverted(_startTime, null, { digits: 0 });
|
|
1093
|
+
const contentLengthDigits = logOptions.contentLengthDigits || logger.contentLengthDigits || defaults.contentLengthDigits;
|
|
1094
|
+
const contentLength = _.isNumber(_contentLength) ? `- ${ convertBytes(_contentLength, { digits: contentLengthDigits }) }` : null;
|
|
1095
|
+
const parts = [ prefix, operation, dn, filter, statusCode, status, responseTime, contentLength ];
|
|
1096
|
+
const message = _.compact(parts).join(' ');
|
|
1097
|
+
logger[ logLevel ](message, { ldap: true } );
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1061
1100
|
}
|
|
1062
1101
|
|
|
1063
1102
|
module.exports = ZeddemoreLogger;
|
package/lib/color.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// Copyright (c) 2024-
|
|
1
|
+
// Copyright (c) 2024-2026 by Beardon Services, Inc.
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
|
+
const { stripVTControlCharacters } = require('node:util');
|
|
5
6
|
|
|
6
7
|
const colorMappings = require('./mappings/color_mappings');
|
|
7
8
|
const enums = require('./enums');
|
|
@@ -43,7 +44,16 @@ function chalkHex(hexColor, layer = cl.FOREGROUND, string) {
|
|
|
43
44
|
|
|
44
45
|
function chalkHttpStatuses(statusCode, string = null) {
|
|
45
46
|
if (!string) string = statusCode;
|
|
46
|
-
const colorMap = _.find(colorMappings.httpStatusColors, (httpStatusColor) => httpStatusColor.range.includes(
|
|
47
|
+
const colorMap = _.find(colorMappings.httpStatusColors, (httpStatusColor) => httpStatusColor.range.includes(statusCode));
|
|
48
|
+
if (!colorMap || !colorMap.style) return string;
|
|
49
|
+
let chalkedMatch = string;
|
|
50
|
+
if (colorMap.style.fore) chalkedMatch = `\x1B[${ colorMap.style.fore }m${ string }\x1B[39m`;
|
|
51
|
+
return chalkedMatch;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function chalkLdapStatuses(statusCode, string = null) {
|
|
55
|
+
if (!string) string = statusCode;
|
|
56
|
+
const colorMap = _.find(colorMappings.ldapStatusColors, (ldapStatusColor) => ldapStatusColor.range.includes(statusCode));
|
|
47
57
|
if (!colorMap || !colorMap.style) return string;
|
|
48
58
|
let chalkedMatch = string;
|
|
49
59
|
if (colorMap.style.fore) chalkedMatch = `\x1B[${ colorMap.style.fore }m${ string }\x1B[39m`;
|
|
@@ -61,6 +71,10 @@ function chalkMatch(match, string, colorsMap) {
|
|
|
61
71
|
return chalkTarget(string, colorMap.style);
|
|
62
72
|
}
|
|
63
73
|
|
|
74
|
+
function chalkLdapOperation(verb, string = null) {
|
|
75
|
+
return chalkMatch(verb, string, colorMappings.ldapOperationColors);
|
|
76
|
+
}
|
|
77
|
+
|
|
64
78
|
function chalkHttpVerbs(verb, string = null, replaceGlobal = false) {
|
|
65
79
|
if (!string) string = verb;
|
|
66
80
|
return chalkViaColorMap(verb, string, colorMappings.httpVerbColors, replaceGlobal);
|
|
@@ -176,11 +190,18 @@ function stringToIdempotentHslValues(str, hslOptions) {
|
|
|
176
190
|
return { h: hue, s: saturation, l: lightness };
|
|
177
191
|
}
|
|
178
192
|
|
|
193
|
+
function stripChalk(str) {
|
|
194
|
+
return stripVTControlCharacters(str);
|
|
195
|
+
}
|
|
196
|
+
|
|
179
197
|
module.exports = {
|
|
180
198
|
chalkHttpStatuses,
|
|
181
199
|
chalkHttpVerbs,
|
|
200
|
+
chalkLdapStatuses,
|
|
201
|
+
chalkLdapOperation,
|
|
182
202
|
chalkLogLevel,
|
|
183
203
|
chalkPackage,
|
|
184
204
|
chalkTarget,
|
|
185
205
|
stringToIdempotentHexColor,
|
|
206
|
+
stripChalk,
|
|
186
207
|
};
|
package/lib/date.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Copyright (c) 2025 by Beardon Services, Inc.
|
|
1
|
+
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
+
const { DateTime } = require('luxon');
|
|
4
5
|
|
|
5
6
|
function convertFechaDateFormatToLuxon(dateFormat) {
|
|
6
7
|
const tokenMappings = [
|
|
@@ -70,7 +71,29 @@ function convertMilliseconds(milliseconds, options) {
|
|
|
70
71
|
return `${ value.toFixed(digits) }${ spaced ? ' ' : '' }${ unit }`;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
function durationMs(startDate, endDate = DateTime.now()) {
|
|
75
|
+
const luxonStartDate = ldapJsDateToLuxon(startDate);
|
|
76
|
+
const luxonEndDate = ldapJsDateToLuxon(endDate);
|
|
77
|
+
if (_.isNull(luxonStartDate) || _.isNull(luxonEndDate)) return null;
|
|
78
|
+
return luxonEndDate.diff(luxonStartDate, 'milliseconds').milliseconds;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function durationConverted(startDate, endDate = DateTime.now(), options) {
|
|
82
|
+
endDate = (_.isObject(endDate) && endDate.isValid) ? endDate : DateTime.now();
|
|
83
|
+
const ms = durationMs(startDate, endDate);
|
|
84
|
+
if (!_.isInteger(ms)) return null;
|
|
85
|
+
return convertMilliseconds(ms, options)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ldapJsDateToLuxon(date) {
|
|
89
|
+
if (!date) return null;
|
|
90
|
+
if (_.isObject(date) && date.isValid) return date;
|
|
91
|
+
let luxonDate = DateTime.fromMillis(date);
|
|
92
|
+
return (_.isObject(luxonDate) && luxonDate.isValid) ? luxonDate : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
73
95
|
module.exports = {
|
|
74
96
|
convertFechaDateFormatToLuxon,
|
|
75
97
|
convertMilliseconds,
|
|
98
|
+
durationConverted,
|
|
76
99
|
};
|
package/lib/enums.js
CHANGED
|
@@ -13,6 +13,8 @@ const ansiColors = {
|
|
|
13
13
|
HTTP_REDIRECTION: 36, // blue
|
|
14
14
|
HTTP_SERVER_ERROR: 31, // red
|
|
15
15
|
HTTP_SUCCESSFUL: 32, // green
|
|
16
|
+
LDAP_ERROR: 31, // red
|
|
17
|
+
LDAP_SUCCESSFUL: 32, // green
|
|
16
18
|
LOG_LEVEL_DEBUG: 34, // blue
|
|
17
19
|
LOG_LEVEL_ERROR: 31, // red
|
|
18
20
|
LOG_LEVEL_HTTP: 32, // green
|
|
@@ -51,6 +53,17 @@ const hexColors = {
|
|
|
51
53
|
HTTP_POST: '#F4DA7A',
|
|
52
54
|
HTTP_PUT: '#74AEF6',
|
|
53
55
|
HTTP_TRACE: '#FFFFFF',
|
|
56
|
+
LDAP_ABANDON: '#922B21',
|
|
57
|
+
LDAP_ADD: '#F1C40F',
|
|
58
|
+
LDAP_BIND: '#2ECC71',
|
|
59
|
+
LDAP_COMPARE: '#A3E4D7',
|
|
60
|
+
LDAP_DELETE: '#E74C3C',
|
|
61
|
+
LDAP_EXTENDED: '#ECF0F1',
|
|
62
|
+
LDAP_MODIFY: '#F39C12',
|
|
63
|
+
LDAP_MODIFY_DN: '#9B59B6',
|
|
64
|
+
LDAP_SEARCH: '#1ABC9C',
|
|
65
|
+
LDAP_UNBIND: '#7F8C8D',
|
|
66
|
+
LIGHT_GRAY: '#777B7E',
|
|
54
67
|
PACKAGE_ANGULARJS: '#C04737',
|
|
55
68
|
PACKAGE_AXIOS: '#6200e1',
|
|
56
69
|
PACKAGE_EXPRESS: '#F7DF1E',
|
|
@@ -102,6 +115,32 @@ const httpResponseHeaders = {
|
|
|
102
115
|
CONTENT_LENGTH: 'Content-Length',
|
|
103
116
|
};
|
|
104
117
|
|
|
118
|
+
const ldapOperations = {
|
|
119
|
+
ABANDON: 'ABANDON',
|
|
120
|
+
ADD: 'ADD',
|
|
121
|
+
BIND: 'BIND',
|
|
122
|
+
COMPARE: 'COMPARE',
|
|
123
|
+
DELETE: 'DEL',
|
|
124
|
+
EXTENDED: 'EXTENDED',
|
|
125
|
+
MODIFY: 'MODIFY',
|
|
126
|
+
MODIFY_DN: 'MODIFYDN',
|
|
127
|
+
SEARCH: 'SEARCH',
|
|
128
|
+
UNBIND: 'UNBIND',
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const ldapRequestOperationTypes = {
|
|
132
|
+
ABANDON: 'AbandonRequest',
|
|
133
|
+
ADD: 'AddRequest',
|
|
134
|
+
BIND: 'BindRequest',
|
|
135
|
+
COMPARE: 'CompareRequest',
|
|
136
|
+
DELETE: 'DelRequest',
|
|
137
|
+
EXTENDED: 'ExtendedRequest',
|
|
138
|
+
MODIFY: 'ModifyRequest',
|
|
139
|
+
MODIFY_DN: 'ModifyDNRequest',
|
|
140
|
+
SEARCH: 'SearchRequest',
|
|
141
|
+
UNBIND: 'UnbindRequest',
|
|
142
|
+
};
|
|
143
|
+
|
|
105
144
|
const logLevelTypes = {
|
|
106
145
|
CONSOLE: 'console',
|
|
107
146
|
EMAIL: 'email',
|
|
@@ -155,6 +194,7 @@ const winstonLogLevelNames = {
|
|
|
155
194
|
WARNING: 'warn',
|
|
156
195
|
INFO: 'info',
|
|
157
196
|
HTTP: 'http',
|
|
197
|
+
LDAP: 'ldap',
|
|
158
198
|
VERBOSE: 'verbose',
|
|
159
199
|
DEBUG: 'debug',
|
|
160
200
|
SILLY: 'silly',
|
|
@@ -197,6 +237,8 @@ module.exports = {
|
|
|
197
237
|
httpMethods,
|
|
198
238
|
httpRequestHeaders,
|
|
199
239
|
httpResponseHeaders,
|
|
240
|
+
ldapOperations,
|
|
241
|
+
ldapRequestOperationTypes,
|
|
200
242
|
logLevelTypes,
|
|
201
243
|
morganFormats,
|
|
202
244
|
morganFormatTokens,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const enums = require('../enums');
|
|
5
5
|
|
|
6
|
-
const { ansiColors: ac, chalkFormats: cf, hexColors: hc, httpMethods: http, winstonLogLevelNames: wlln } = enums;
|
|
6
|
+
const { ansiColors: ac, chalkFormats: cf, hexColors: hc, httpMethods: http, ldapOperations: lo, winstonLogLevelNames: wlln } = enums;
|
|
7
7
|
|
|
8
8
|
const httpStatusColors = [
|
|
9
9
|
{ range: _.range(500, 600), style: { format: cf.ANSI, fore: ac.HTTP_SERVER_ERROR, back: null } },
|
|
@@ -25,6 +25,24 @@ const httpVerbColors = [
|
|
|
25
25
|
{ match: http.TRACE, style: { format: cf.HEX, fore: hc.BLACK, back: hc.HTTP_TRACE } },
|
|
26
26
|
];
|
|
27
27
|
|
|
28
|
+
const ldapStatusColors = [
|
|
29
|
+
{ range: _.range(1, 999), style: { format: cf.ANSI, fore: ac.LDAP_ERROR, back: null } },
|
|
30
|
+
{ range: [ 0 ], style: { format: cf.ANSI, fore: ac.LDAP_SUCCESSFUL, back: null } },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const ldapOperationColors = [
|
|
34
|
+
{ match: lo.ABANDON, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_ABANDON } },
|
|
35
|
+
{ match: lo.ADD, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_ADD } },
|
|
36
|
+
{ match: lo.BIND, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_BIND } },
|
|
37
|
+
{ match: lo.COMPARE, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_COMPARE } },
|
|
38
|
+
{ match: lo.DELETE, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_DELETE } },
|
|
39
|
+
{ match: lo.EXTENDED, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_EXTENDED } },
|
|
40
|
+
{ match: lo.MODIFY, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_MODIFY } },
|
|
41
|
+
{ match: lo.MODIFY_DN, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_MODIFY_DN } },
|
|
42
|
+
{ match: lo.SEARCH, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_SEARCH } },
|
|
43
|
+
{ match: lo.UNBIND, style: { format: cf.HEX, fore: hc.BLACK, back: hc.LDAP_UNBIND } },
|
|
44
|
+
];
|
|
45
|
+
|
|
28
46
|
const logLevelColors = [
|
|
29
47
|
{ match: wlln.ERROR, style: { format: cf.ANSI, fore: ac.LOG_LEVEL_ERROR, back: null } },
|
|
30
48
|
{ match: wlln.WARNING, style: { format: cf.ANSI, fore: ac.LOG_LEVEL_WARNING, back: null } },
|
|
@@ -55,6 +73,8 @@ const packageColors = [
|
|
|
55
73
|
module.exports = {
|
|
56
74
|
httpStatusColors,
|
|
57
75
|
httpVerbColors,
|
|
76
|
+
ldapOperationColors,
|
|
77
|
+
ldapStatusColors,
|
|
58
78
|
logLevelColors,
|
|
59
79
|
packageColors,
|
|
60
80
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) 2026 by Beardon Services, Inc.
|
|
2
|
+
|
|
3
|
+
const enums = require('../enums');
|
|
4
|
+
|
|
5
|
+
const { ldapOperations: lo, ldapRequestOperationTypes: lrot } = enums;
|
|
6
|
+
|
|
7
|
+
const ldapRequestOperationMap = [
|
|
8
|
+
{ operation: lo.ABANDON, type: lrot.ABANDON },
|
|
9
|
+
{ operation: lo.ADD, type: lrot.ADD },
|
|
10
|
+
{ operation: lo.BIND, type: lrot.BIND },
|
|
11
|
+
{ operation: lo.COMPARE, type: lrot.COMPARE },
|
|
12
|
+
{ operation: lo.DELETE, type: lrot.DELETE },
|
|
13
|
+
{ operation: lo.EXTENDED, type: lrot.EXTENDED },
|
|
14
|
+
{ operation: lo.MODIFY, type: lrot.MODIFY },
|
|
15
|
+
{ operation: lo.MODIFY_DN, type: lrot.MODIFY_DN },
|
|
16
|
+
{ operation: lo.SEARCH, type: lrot.SEARCH },
|
|
17
|
+
{ operation: lo.UNBIND, type: lrot.UNBIND },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
ldapRequestOperationMap,
|
|
22
|
+
};
|
package/lib/math.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// Copyright (c) 2025 by Beardon Services, Inc.
|
|
1
|
+
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
+
const sizeof = require('object-sizeof');
|
|
4
5
|
|
|
5
6
|
function convertBytes(bytes, options = { }) {
|
|
6
7
|
options = options || { };
|
|
7
|
-
if (!bytes) return null;
|
|
8
|
+
if (!_.isNumber(bytes)) return null;
|
|
8
9
|
const useBinaryUnits = _.isBoolean(options.useBinaryUnits) ? options.useBinaryUnits : false;
|
|
9
10
|
const decimals = _.isInteger(options.decimals) ? options.decimals : 2;
|
|
10
11
|
const spaced = _.isBoolean(options.spaced) ? options.spaced : false;
|
|
@@ -12,11 +13,17 @@ function convertBytes(bytes, options = { }) {
|
|
|
12
13
|
const units = useBinaryUnits
|
|
13
14
|
? [ 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' ]
|
|
14
15
|
: [ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ];
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
let i = Math.floor(Math.log(bytes) / Math.log(base));
|
|
17
|
+
if (!_.isSafeInteger(i)) i = 0;
|
|
18
|
+
let size = (bytes / Math.pow(base, i)).toFixed(decimals);
|
|
19
|
+
if (_.isNaN(size)) size = 0;
|
|
17
20
|
return `${ size }${ spaced ? ' ' : '' }${ units[ i ] }`;
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
function objectBytes(object) {
|
|
24
|
+
return !_.isNull(object) ? sizeof(object) : 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
function round(value, decimals = 2) {
|
|
21
28
|
if (!_.isNumber(value)) return value;
|
|
22
29
|
const rounder = Math.pow(10, decimals);
|
|
@@ -25,5 +32,6 @@ function round(value, decimals = 2) {
|
|
|
25
32
|
|
|
26
33
|
module.exports = {
|
|
27
34
|
convertBytes,
|
|
35
|
+
objectBytes,
|
|
28
36
|
round,
|
|
29
37
|
};
|
package/lib/zeddemore-logger.js
CHANGED
|
@@ -12,5 +12,6 @@ module.exports = {
|
|
|
12
12
|
writeAxiosErrorLog: ZeddemoreLogger.writeAxiosErrorLog,
|
|
13
13
|
writeAxiosLog: ZeddemoreLogger.writeAxiosResponseLog, // deprecated
|
|
14
14
|
writeAxiosResponseLog: ZeddemoreLogger.writeAxiosResponseLog,
|
|
15
|
+
writeLdapResponseLog: ZeddemoreLogger.writeLdapResponseLog,
|
|
15
16
|
ZeddemoreLogger,
|
|
16
17
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zeddemore-logger",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Node.js
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Node.js logger using Morgan and Winston for thread and caller info tracking",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/beardon/zeddemore-logger.git"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"nodemailer": "^9.0.3",
|
|
29
29
|
"object-sizeof": "^2.6.5",
|
|
30
30
|
"uuid": "^11.1.1",
|
|
31
|
-
"winston": "^3.
|
|
31
|
+
"winston": "^3.19.0",
|
|
32
32
|
"winston-transport": "^4.9.0"
|
|
33
33
|
}
|
|
34
34
|
}
|