zeddemore-logger 2.3.1 → 2.3.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/.github/workflows/publish.yml +31 -0
- package/README.md +3 -3
- package/lib/ZeddemoreLogger.js +14 -9
- package/lib/defaults.js +3 -3
- package/lib/enums.js +250 -250
- package/lib/http.js +26 -26
- package/lib/request.js +68 -68
- package/lib/transports/WinstonEmailTransport.js +127 -127
- package/lib/typedef.js +33 -33
- package/package.json +41 -34
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
tags:
|
|
7
|
+
- 'v[0-9]*.[0-9]*.[0-9]*'
|
|
8
|
+
- 'v[0-9]*.[0-9]*.[0-9]*-*'
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
id-token: write # Required for npm provenance tracking
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout repository
|
|
19
|
+
uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Setup Node.js
|
|
22
|
+
uses: actions/setup-node@v4
|
|
23
|
+
with:
|
|
24
|
+
node-version: '24'
|
|
25
|
+
registry-url: 'https://registry.npmjs.org'
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: npm ci
|
|
29
|
+
|
|
30
|
+
- name: Publish package
|
|
31
|
+
run: npm publish --provenance --access public
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# zeddemore-logger
|
|
2
|
-
|
|
3
|
-
Node.js logger using Morgan and Winston for thread and caller info tracking.
|
|
1
|
+
# zeddemore-logger
|
|
2
|
+
|
|
3
|
+
Node.js logger using Morgan and Winston for thread and caller info tracking.
|
package/lib/ZeddemoreLogger.js
CHANGED
|
@@ -750,8 +750,10 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
750
750
|
/**
|
|
751
751
|
* Log server listening information
|
|
752
752
|
* @param {Object} options
|
|
753
|
+
* @param {String} [options.address]
|
|
753
754
|
* @param {String} [options.environment]
|
|
754
|
-
* @param {String} [options.
|
|
755
|
+
* @param {String} [options.family]
|
|
756
|
+
* @param {String} [options.listenHost] - @deprecated Use options.address instead
|
|
755
757
|
* @param {String} [options.instance]
|
|
756
758
|
* @param {String} [options.name]
|
|
757
759
|
* @param {number} [options.port]
|
|
@@ -760,20 +762,23 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
760
762
|
*/
|
|
761
763
|
#logServerListening = (options, logLevel = wll.INFO) => {
|
|
762
764
|
const serverEnvironment = options.environment || this.serverEnvironment;
|
|
763
|
-
const
|
|
765
|
+
const serverAddress = options.address || options.listenHost || defaults.address;
|
|
766
|
+
let serverFamily = options.family || null;
|
|
764
767
|
const serverInstance = options.instance || this.serverInstance;
|
|
765
768
|
const serverName = options.name || this.serverName;
|
|
766
769
|
const serverPort = options.port || this.serverPort;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
+
if (_.isNull(serverFamily)) {
|
|
771
|
+
const usingIPv4 = true;
|
|
772
|
+
const usingIPv6 = _.isString(serverAddress) && serverAddress.includes(defaults.addressIPv6Sentinel);
|
|
773
|
+
serverFamily = _.compact([ (usingIPv4 ? 'IPv4' : null), (usingIPv6 ? chalk.red('IPv6') : null) ]).join('/');
|
|
774
|
+
}
|
|
770
775
|
const msgParts = [ ];
|
|
771
776
|
const serverParts = [ serverName ];
|
|
772
|
-
if (serverEnvironment) serverParts.push(serverEnvironment);
|
|
777
|
+
if (serverEnvironment) serverParts.push(chalk.bold(serverEnvironment));
|
|
773
778
|
if (serverInstance) serverParts.push(serverInstance);
|
|
774
779
|
msgParts.push(`[${ serverParts.join(':') }]`);
|
|
775
|
-
msgParts.push(`Node.js server listening on ${
|
|
776
|
-
msgParts.push(`(${
|
|
780
|
+
msgParts.push(`Node.js server listening on ${ serverAddress }:${ chalk.bold(serverPort) }`);
|
|
781
|
+
msgParts.push(`(${ serverFamily })`);
|
|
777
782
|
this.log(logLevel)(msgParts.join(' '));
|
|
778
783
|
}
|
|
779
784
|
|
|
@@ -867,7 +872,7 @@ class ZeddemoreLogger extends ZeddemoreBase {
|
|
|
867
872
|
* @param {String} [options.morganFormat]
|
|
868
873
|
* @returns {function(*, *, *): void}
|
|
869
874
|
*/
|
|
870
|
-
morganMiddleware = (options) => {
|
|
875
|
+
morganMiddleware = (options = { }) => {
|
|
871
876
|
options = options || { };
|
|
872
877
|
const colorize = _.isBoolean(options.colorize) ? options.colorize : this.colorize;
|
|
873
878
|
const disableMorganLogging = _.isBoolean(options.disableMorganLogging) ? options.disableMorganLogging : !this.httpRequestLogging;
|
package/lib/defaults.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright (c) 2024-
|
|
1
|
+
// Copyright (c) 2024-2026 by Beardon Services, Inc.
|
|
2
2
|
|
|
3
3
|
const enums = require('./enums');
|
|
4
4
|
|
|
@@ -6,14 +6,14 @@ const { hexColors: hc, logLevelTypes: llt, morganFormats: mf, morganFormatTokens
|
|
|
6
6
|
winstonLogLevelNames: wlln, winstonTransports: wt } = enums;
|
|
7
7
|
|
|
8
8
|
module.exports = {
|
|
9
|
+
address: '::',
|
|
10
|
+
addressIPv6Sentinel: ':',
|
|
9
11
|
colorConsoleWhiteHex: hc.CONSOLE_WHITE,
|
|
10
12
|
consoleDirExtensionMethodName: 'dirp',
|
|
11
13
|
consoleDirExtensionColors: true,
|
|
12
14
|
consoleDirExtensionDepth: null,
|
|
13
15
|
consoleDirExtensionShowHidden: true,
|
|
14
16
|
contentLengthDigits: 2,
|
|
15
|
-
listenHost: '::',
|
|
16
|
-
listenHostIPv6Sentinel: ':',
|
|
17
17
|
liveMessage: 'live',
|
|
18
18
|
logLevelType: llt.CONSOLE,
|
|
19
19
|
morganFormat: mf.ZEDDEMORE,
|
package/lib/enums.js
CHANGED
|
@@ -1,250 +1,250 @@
|
|
|
1
|
-
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
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
|
-
|
|
10
|
-
const ansiColors = {
|
|
11
|
-
HTTP_CLIENT_ERROR: 33, // red
|
|
12
|
-
HTTP_INFORMATIONAL: 0, // white
|
|
13
|
-
HTTP_REDIRECTION: 36, // blue
|
|
14
|
-
HTTP_SERVER_ERROR: 31, // red
|
|
15
|
-
HTTP_SUCCESSFUL: 32, // green
|
|
16
|
-
LDAP_ERROR: 31, // red
|
|
17
|
-
LDAP_SUCCESSFUL: 32, // green
|
|
18
|
-
LOG_LEVEL_DEBUG: 34, // blue
|
|
19
|
-
LOG_LEVEL_ERROR: 31, // red
|
|
20
|
-
LOG_LEVEL_HTTP: 32, // green
|
|
21
|
-
LOG_LEVEL_INFO: 32, // green
|
|
22
|
-
LOG_LEVEL_SILLY: 35, // magenta
|
|
23
|
-
LOG_LEVEL_VERBOSE: 36, // cyan
|
|
24
|
-
LOG_LEVEL_WARNING: 33, // yellow
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const chalkFormats = {
|
|
28
|
-
ANSI: 'ansi',
|
|
29
|
-
HEX: 'hex',
|
|
30
|
-
RGB: 'rgb',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const chalkLayers = {
|
|
34
|
-
BACKGROUND: 'bg',
|
|
35
|
-
FOREGROUND: 'fg',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const hexColors = {
|
|
39
|
-
BEARDON_RED: '#951A1D',
|
|
40
|
-
BLACK: '#000000',
|
|
41
|
-
CONSOLE_WHITE: '#ECECEC',
|
|
42
|
-
DB_DELETE: '#F22613',
|
|
43
|
-
DB_INSERT: '#00B16A',
|
|
44
|
-
DB_SELECT: '#1E90FF',
|
|
45
|
-
DB_TRUNCATE: '#750505',
|
|
46
|
-
DB_UPDATE: '#F9690E',
|
|
47
|
-
HTTP_CONNECT: '#FFFFFF',
|
|
48
|
-
HTTP_DELETE: '#EF968A',
|
|
49
|
-
HTTP_GET: '#67D193',
|
|
50
|
-
HTTP_HEAD: '#68D696',
|
|
51
|
-
HTTP_OPTIONS: '#E55AA8',
|
|
52
|
-
HTTP_PATCH: '#C0A8E1',
|
|
53
|
-
HTTP_POST: '#F4DA7A',
|
|
54
|
-
HTTP_PUT: '#74AEF6',
|
|
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',
|
|
67
|
-
PACKAGE_ANGULARJS: '#C04737',
|
|
68
|
-
PACKAGE_AXIOS: '#6200e1',
|
|
69
|
-
PACKAGE_EXPRESS: '#F7DF1E',
|
|
70
|
-
PACKAGE_HANDLEBARS: '#F0772B',
|
|
71
|
-
PACKAGE_JIMP: '#FF0000',
|
|
72
|
-
PACKAGE_MYSQL: '#00618A',
|
|
73
|
-
PACKAGE_NODE_JS: '#689F63',
|
|
74
|
-
PACKAGE_NODEMAILER: '#29ABE2',
|
|
75
|
-
PACKAGE_PASSPORT: '#51E492',
|
|
76
|
-
PACKAGE_PDFKIT: '#DB000D',
|
|
77
|
-
PACKAGE_POSTGRESQL: '#336791',
|
|
78
|
-
PACKAGE_REDIS: '#C23936',
|
|
79
|
-
PACKAGE_SEQUELIZE: '#00AFEF',
|
|
80
|
-
PACKAGE_ZEDDEMORE: '#E2B68F',
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const httpStatusCodeGroups = {
|
|
84
|
-
INFORMATIONAL: 1,
|
|
85
|
-
SUCCESSFUL: 2,
|
|
86
|
-
REDIRECTION: 3,
|
|
87
|
-
CLIENT_ERROR: 4,
|
|
88
|
-
SERVER_ERROR: 5,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const httpMethods = {
|
|
92
|
-
GET: 'GET',
|
|
93
|
-
HEAD: 'HEAD',
|
|
94
|
-
POST: 'POST',
|
|
95
|
-
PUT: 'PUT',
|
|
96
|
-
DELETE: 'DELETE',
|
|
97
|
-
CONNECT: 'CONNECT',
|
|
98
|
-
OPTIONS: 'OPTIONS',
|
|
99
|
-
TRACE: 'TRACE',
|
|
100
|
-
PATCH: 'PATCH',
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const httpRequestHeaders = {
|
|
104
|
-
ACCEPT_LANGUAGE: 'Accept-Language',
|
|
105
|
-
ALLOW: 'Allow',
|
|
106
|
-
APP_VERSION: 'App-Version',
|
|
107
|
-
AUTHORIZATION: 'Authorization',
|
|
108
|
-
BEARER_PREFIX: 'Bearer',
|
|
109
|
-
FORWARDED_FOR: 'X-Forwarded-For',
|
|
110
|
-
REQUEST_ID: 'X-Request-Id',
|
|
111
|
-
USER_AGENT: 'User-Agent',
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const httpResponseHeaders = {
|
|
115
|
-
CONTENT_LENGTH: 'Content-Length',
|
|
116
|
-
};
|
|
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: 'MODIFY_DN',
|
|
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: 'DeleteRequest',
|
|
137
|
-
EXTENDED: 'ExtendedRequest',
|
|
138
|
-
MODIFY: 'ModifyRequest',
|
|
139
|
-
MODIFY_DN: 'ModifyDnRequest',
|
|
140
|
-
SEARCH: 'SearchRequest',
|
|
141
|
-
UNBIND: 'UnbindRequest',
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const logLevelTypes = {
|
|
145
|
-
CONSOLE: 'console',
|
|
146
|
-
EMAIL: 'email',
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const morganFormats = {
|
|
150
|
-
COMBINED: 'combined',
|
|
151
|
-
COMMON: 'common',
|
|
152
|
-
DEV: 'dev',
|
|
153
|
-
SHORT: 'short',
|
|
154
|
-
TINY: 'tiny',
|
|
155
|
-
ZEDDEMORE: 'zeddemore', // added for `zeddemore-logger`
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const morganFormatTokens = {
|
|
159
|
-
CONTENT_LENGTH_FORMAT: 'content-length-format', // added for `zeddemore-logger`
|
|
160
|
-
DATE: 'date', // :date[format]
|
|
161
|
-
DECODED_URL: 'decoded-url', // added for `zeddemore-logger`
|
|
162
|
-
HTTP_VERSION: 'http-version',
|
|
163
|
-
METHOD: 'method',
|
|
164
|
-
REFERRER: 'referrer',
|
|
165
|
-
REMOTE_ADDR: 'remote-addr',
|
|
166
|
-
REMOTE_USER: 'remote-user',
|
|
167
|
-
REQ: 'req', // :req[header]
|
|
168
|
-
RES: 'res', // :res[header]
|
|
169
|
-
RESPONSE_TIME: 'response-time', // :response-time[digits]
|
|
170
|
-
RESPONSE_TIME_FORMAT: 'response-time-format', // added for `zeddemore-logger`
|
|
171
|
-
STATUS: 'status',
|
|
172
|
-
STATUS_COLORED: 'status-colored', // added for `zeddemore-logger`
|
|
173
|
-
TOTAL_TIME: 'total-time', // :total-time[digits]
|
|
174
|
-
URL: 'url',
|
|
175
|
-
USER_AGENT: 'user-agent',
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const winstonFormats = {
|
|
179
|
-
COLORIZE: 'colorize',
|
|
180
|
-
JSON: 'json',
|
|
181
|
-
METADATA: 'metadata',
|
|
182
|
-
PRETTY_PRINT: 'pretty_print',
|
|
183
|
-
SIMPLE: 'simple',
|
|
184
|
-
SPLAT: 'splat',
|
|
185
|
-
TIMESTAMP: 'timestamp',
|
|
186
|
-
ZEDDEMORE_INFO_MUTATION: 'zeddemore_info_mutation',
|
|
187
|
-
ZEDDEMORE_LABEL: 'zeddemore_label',
|
|
188
|
-
ZEDDEMORE_PRINTF: 'zeddemore_printf',
|
|
189
|
-
ZEDDEMORE_TIMESTAMP: 'zeddemore_timestamp',
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const winstonLogLevelNames = {
|
|
193
|
-
ERROR: 'error',
|
|
194
|
-
WARNING: 'warn',
|
|
195
|
-
INFO: 'info',
|
|
196
|
-
HTTP: 'http',
|
|
197
|
-
LDAP: 'ldap',
|
|
198
|
-
VERBOSE: 'verbose',
|
|
199
|
-
DEBUG: 'debug',
|
|
200
|
-
SILLY: 'silly',
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// using NPM logging levels
|
|
204
|
-
const winstonLogLevels = {
|
|
205
|
-
ERROR: 0,
|
|
206
|
-
WARNING: 1,
|
|
207
|
-
INFO: 2,
|
|
208
|
-
HTTP: 3,
|
|
209
|
-
VERBOSE: 4,
|
|
210
|
-
DEBUG: 5,
|
|
211
|
-
SILLY: 6,
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const winstonTransports = {
|
|
215
|
-
CONSOLE: 'console',
|
|
216
|
-
EMAIL: 'email',
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const zeddemoreLogLevelCaptions = {
|
|
220
|
-
DEFAULT: 'Default',
|
|
221
|
-
ERROR: 'Error',
|
|
222
|
-
WARNING: 'Warning',
|
|
223
|
-
INFO: 'Info',
|
|
224
|
-
HTTP: 'HTTP',
|
|
225
|
-
VERBOSE: 'Verbose',
|
|
226
|
-
DEBUG: 'Debug',
|
|
227
|
-
SILLY: 'Silly',
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
module.exports = {
|
|
231
|
-
doesEnumInclude,
|
|
232
|
-
ansiColors,
|
|
233
|
-
chalkFormats,
|
|
234
|
-
chalkLayers,
|
|
235
|
-
hexColors,
|
|
236
|
-
httpStatusCodeGroups,
|
|
237
|
-
httpMethods,
|
|
238
|
-
httpRequestHeaders,
|
|
239
|
-
httpResponseHeaders,
|
|
240
|
-
ldapOperations,
|
|
241
|
-
ldapRequestOperationTypes,
|
|
242
|
-
logLevelTypes,
|
|
243
|
-
morganFormats,
|
|
244
|
-
morganFormatTokens,
|
|
245
|
-
winstonFormats,
|
|
246
|
-
winstonLogLevelNames,
|
|
247
|
-
winstonLogLevels,
|
|
248
|
-
winstonTransports,
|
|
249
|
-
zeddemoreLogLevelCaptions,
|
|
250
|
-
};
|
|
1
|
+
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
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
|
+
|
|
10
|
+
const ansiColors = {
|
|
11
|
+
HTTP_CLIENT_ERROR: 33, // red
|
|
12
|
+
HTTP_INFORMATIONAL: 0, // white
|
|
13
|
+
HTTP_REDIRECTION: 36, // blue
|
|
14
|
+
HTTP_SERVER_ERROR: 31, // red
|
|
15
|
+
HTTP_SUCCESSFUL: 32, // green
|
|
16
|
+
LDAP_ERROR: 31, // red
|
|
17
|
+
LDAP_SUCCESSFUL: 32, // green
|
|
18
|
+
LOG_LEVEL_DEBUG: 34, // blue
|
|
19
|
+
LOG_LEVEL_ERROR: 31, // red
|
|
20
|
+
LOG_LEVEL_HTTP: 32, // green
|
|
21
|
+
LOG_LEVEL_INFO: 32, // green
|
|
22
|
+
LOG_LEVEL_SILLY: 35, // magenta
|
|
23
|
+
LOG_LEVEL_VERBOSE: 36, // cyan
|
|
24
|
+
LOG_LEVEL_WARNING: 33, // yellow
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const chalkFormats = {
|
|
28
|
+
ANSI: 'ansi',
|
|
29
|
+
HEX: 'hex',
|
|
30
|
+
RGB: 'rgb',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const chalkLayers = {
|
|
34
|
+
BACKGROUND: 'bg',
|
|
35
|
+
FOREGROUND: 'fg',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const hexColors = {
|
|
39
|
+
BEARDON_RED: '#951A1D',
|
|
40
|
+
BLACK: '#000000',
|
|
41
|
+
CONSOLE_WHITE: '#ECECEC',
|
|
42
|
+
DB_DELETE: '#F22613',
|
|
43
|
+
DB_INSERT: '#00B16A',
|
|
44
|
+
DB_SELECT: '#1E90FF',
|
|
45
|
+
DB_TRUNCATE: '#750505',
|
|
46
|
+
DB_UPDATE: '#F9690E',
|
|
47
|
+
HTTP_CONNECT: '#FFFFFF',
|
|
48
|
+
HTTP_DELETE: '#EF968A',
|
|
49
|
+
HTTP_GET: '#67D193',
|
|
50
|
+
HTTP_HEAD: '#68D696',
|
|
51
|
+
HTTP_OPTIONS: '#E55AA8',
|
|
52
|
+
HTTP_PATCH: '#C0A8E1',
|
|
53
|
+
HTTP_POST: '#F4DA7A',
|
|
54
|
+
HTTP_PUT: '#74AEF6',
|
|
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',
|
|
67
|
+
PACKAGE_ANGULARJS: '#C04737',
|
|
68
|
+
PACKAGE_AXIOS: '#6200e1',
|
|
69
|
+
PACKAGE_EXPRESS: '#F7DF1E',
|
|
70
|
+
PACKAGE_HANDLEBARS: '#F0772B',
|
|
71
|
+
PACKAGE_JIMP: '#FF0000',
|
|
72
|
+
PACKAGE_MYSQL: '#00618A',
|
|
73
|
+
PACKAGE_NODE_JS: '#689F63',
|
|
74
|
+
PACKAGE_NODEMAILER: '#29ABE2',
|
|
75
|
+
PACKAGE_PASSPORT: '#51E492',
|
|
76
|
+
PACKAGE_PDFKIT: '#DB000D',
|
|
77
|
+
PACKAGE_POSTGRESQL: '#336791',
|
|
78
|
+
PACKAGE_REDIS: '#C23936',
|
|
79
|
+
PACKAGE_SEQUELIZE: '#00AFEF',
|
|
80
|
+
PACKAGE_ZEDDEMORE: '#E2B68F',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const httpStatusCodeGroups = {
|
|
84
|
+
INFORMATIONAL: 1,
|
|
85
|
+
SUCCESSFUL: 2,
|
|
86
|
+
REDIRECTION: 3,
|
|
87
|
+
CLIENT_ERROR: 4,
|
|
88
|
+
SERVER_ERROR: 5,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const httpMethods = {
|
|
92
|
+
GET: 'GET',
|
|
93
|
+
HEAD: 'HEAD',
|
|
94
|
+
POST: 'POST',
|
|
95
|
+
PUT: 'PUT',
|
|
96
|
+
DELETE: 'DELETE',
|
|
97
|
+
CONNECT: 'CONNECT',
|
|
98
|
+
OPTIONS: 'OPTIONS',
|
|
99
|
+
TRACE: 'TRACE',
|
|
100
|
+
PATCH: 'PATCH',
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const httpRequestHeaders = {
|
|
104
|
+
ACCEPT_LANGUAGE: 'Accept-Language',
|
|
105
|
+
ALLOW: 'Allow',
|
|
106
|
+
APP_VERSION: 'App-Version',
|
|
107
|
+
AUTHORIZATION: 'Authorization',
|
|
108
|
+
BEARER_PREFIX: 'Bearer',
|
|
109
|
+
FORWARDED_FOR: 'X-Forwarded-For',
|
|
110
|
+
REQUEST_ID: 'X-Request-Id',
|
|
111
|
+
USER_AGENT: 'User-Agent',
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const httpResponseHeaders = {
|
|
115
|
+
CONTENT_LENGTH: 'Content-Length',
|
|
116
|
+
};
|
|
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: 'MODIFY_DN',
|
|
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: 'DeleteRequest',
|
|
137
|
+
EXTENDED: 'ExtendedRequest',
|
|
138
|
+
MODIFY: 'ModifyRequest',
|
|
139
|
+
MODIFY_DN: 'ModifyDnRequest',
|
|
140
|
+
SEARCH: 'SearchRequest',
|
|
141
|
+
UNBIND: 'UnbindRequest',
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const logLevelTypes = {
|
|
145
|
+
CONSOLE: 'console',
|
|
146
|
+
EMAIL: 'email',
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const morganFormats = {
|
|
150
|
+
COMBINED: 'combined',
|
|
151
|
+
COMMON: 'common',
|
|
152
|
+
DEV: 'dev',
|
|
153
|
+
SHORT: 'short',
|
|
154
|
+
TINY: 'tiny',
|
|
155
|
+
ZEDDEMORE: 'zeddemore', // added for `zeddemore-logger`
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const morganFormatTokens = {
|
|
159
|
+
CONTENT_LENGTH_FORMAT: 'content-length-format', // added for `zeddemore-logger`
|
|
160
|
+
DATE: 'date', // :date[format]
|
|
161
|
+
DECODED_URL: 'decoded-url', // added for `zeddemore-logger`
|
|
162
|
+
HTTP_VERSION: 'http-version',
|
|
163
|
+
METHOD: 'method',
|
|
164
|
+
REFERRER: 'referrer',
|
|
165
|
+
REMOTE_ADDR: 'remote-addr',
|
|
166
|
+
REMOTE_USER: 'remote-user',
|
|
167
|
+
REQ: 'req', // :req[header]
|
|
168
|
+
RES: 'res', // :res[header]
|
|
169
|
+
RESPONSE_TIME: 'response-time', // :response-time[digits]
|
|
170
|
+
RESPONSE_TIME_FORMAT: 'response-time-format', // added for `zeddemore-logger`
|
|
171
|
+
STATUS: 'status',
|
|
172
|
+
STATUS_COLORED: 'status-colored', // added for `zeddemore-logger`
|
|
173
|
+
TOTAL_TIME: 'total-time', // :total-time[digits]
|
|
174
|
+
URL: 'url',
|
|
175
|
+
USER_AGENT: 'user-agent',
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const winstonFormats = {
|
|
179
|
+
COLORIZE: 'colorize',
|
|
180
|
+
JSON: 'json',
|
|
181
|
+
METADATA: 'metadata',
|
|
182
|
+
PRETTY_PRINT: 'pretty_print',
|
|
183
|
+
SIMPLE: 'simple',
|
|
184
|
+
SPLAT: 'splat',
|
|
185
|
+
TIMESTAMP: 'timestamp',
|
|
186
|
+
ZEDDEMORE_INFO_MUTATION: 'zeddemore_info_mutation',
|
|
187
|
+
ZEDDEMORE_LABEL: 'zeddemore_label',
|
|
188
|
+
ZEDDEMORE_PRINTF: 'zeddemore_printf',
|
|
189
|
+
ZEDDEMORE_TIMESTAMP: 'zeddemore_timestamp',
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const winstonLogLevelNames = {
|
|
193
|
+
ERROR: 'error',
|
|
194
|
+
WARNING: 'warn',
|
|
195
|
+
INFO: 'info',
|
|
196
|
+
HTTP: 'http',
|
|
197
|
+
LDAP: 'ldap',
|
|
198
|
+
VERBOSE: 'verbose',
|
|
199
|
+
DEBUG: 'debug',
|
|
200
|
+
SILLY: 'silly',
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// using NPM logging levels
|
|
204
|
+
const winstonLogLevels = {
|
|
205
|
+
ERROR: 0,
|
|
206
|
+
WARNING: 1,
|
|
207
|
+
INFO: 2,
|
|
208
|
+
HTTP: 3,
|
|
209
|
+
VERBOSE: 4,
|
|
210
|
+
DEBUG: 5,
|
|
211
|
+
SILLY: 6,
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const winstonTransports = {
|
|
215
|
+
CONSOLE: 'console',
|
|
216
|
+
EMAIL: 'email',
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const zeddemoreLogLevelCaptions = {
|
|
220
|
+
DEFAULT: 'Default',
|
|
221
|
+
ERROR: 'Error',
|
|
222
|
+
WARNING: 'Warning',
|
|
223
|
+
INFO: 'Info',
|
|
224
|
+
HTTP: 'HTTP',
|
|
225
|
+
VERBOSE: 'Verbose',
|
|
226
|
+
DEBUG: 'Debug',
|
|
227
|
+
SILLY: 'Silly',
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
module.exports = {
|
|
231
|
+
doesEnumInclude,
|
|
232
|
+
ansiColors,
|
|
233
|
+
chalkFormats,
|
|
234
|
+
chalkLayers,
|
|
235
|
+
hexColors,
|
|
236
|
+
httpStatusCodeGroups,
|
|
237
|
+
httpMethods,
|
|
238
|
+
httpRequestHeaders,
|
|
239
|
+
httpResponseHeaders,
|
|
240
|
+
ldapOperations,
|
|
241
|
+
ldapRequestOperationTypes,
|
|
242
|
+
logLevelTypes,
|
|
243
|
+
morganFormats,
|
|
244
|
+
morganFormatTokens,
|
|
245
|
+
winstonFormats,
|
|
246
|
+
winstonLogLevelNames,
|
|
247
|
+
winstonLogLevels,
|
|
248
|
+
winstonTransports,
|
|
249
|
+
zeddemoreLogLevelCaptions,
|
|
250
|
+
};
|
package/lib/http.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
// Copyright (c) 2026 by Beardon Services, Inc.
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
function extractHttpStatusCode(message) {
|
|
6
|
-
if (!_.isString(message) || !message.length) return null;
|
|
7
|
-
// Regex breakdown:
|
|
8
|
-
// \b : Word boundary (ensures we don't grab "12345")
|
|
9
|
-
// [1-5] : Starts with 1 (Info), 2 (Success), 3 (Redirect), 4 (Client Error), or 5 (Server Error)
|
|
10
|
-
// [0-9]{2}: Followed by exactly two digits
|
|
11
|
-
// \b : Ending word boundary
|
|
12
|
-
const match = message.match(/\b[1-5][0-9]{2}\b/);
|
|
13
|
-
return match ? +match[ 0 ] : null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function extractHttpVerb(message) {
|
|
17
|
-
if (!_.isString(message) || !message.length) return null;
|
|
18
|
-
const splitMessage = message.split(' ');
|
|
19
|
-
if (splitMessage.length < 2) return null;
|
|
20
|
-
return message.split(' ')[ 0 ];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
extractHttpStatusCode,
|
|
25
|
-
extractHttpVerb,
|
|
26
|
-
}
|
|
1
|
+
// Copyright (c) 2026 by Beardon Services, Inc.
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
function extractHttpStatusCode(message) {
|
|
6
|
+
if (!_.isString(message) || !message.length) return null;
|
|
7
|
+
// Regex breakdown:
|
|
8
|
+
// \b : Word boundary (ensures we don't grab "12345")
|
|
9
|
+
// [1-5] : Starts with 1 (Info), 2 (Success), 3 (Redirect), 4 (Client Error), or 5 (Server Error)
|
|
10
|
+
// [0-9]{2}: Followed by exactly two digits
|
|
11
|
+
// \b : Ending word boundary
|
|
12
|
+
const match = message.match(/\b[1-5][0-9]{2}\b/);
|
|
13
|
+
return match ? +match[ 0 ] : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function extractHttpVerb(message) {
|
|
17
|
+
if (!_.isString(message) || !message.length) return null;
|
|
18
|
+
const splitMessage = message.split(' ');
|
|
19
|
+
if (splitMessage.length < 2) return null;
|
|
20
|
+
return message.split(' ')[ 0 ];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
extractHttpStatusCode,
|
|
25
|
+
extractHttpVerb,
|
|
26
|
+
}
|
package/lib/request.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
const enums = require('./enums');
|
|
6
|
-
const { parseIpAddress } = require('./ip_address');
|
|
7
|
-
|
|
8
|
-
const { httpRequestHeaders: rqh } = enums;
|
|
9
|
-
|
|
10
|
-
function extractToken(req) {
|
|
11
|
-
let token;
|
|
12
|
-
const authHeader = req.header(rqh.AUTHORIZATION);
|
|
13
|
-
if (authHeader && authHeader.startsWith(`${ rqh.BEARER_PREFIX } `)) {
|
|
14
|
-
token = req.header(rqh.AUTHORIZATION).split(' ')[ 1 ];
|
|
15
|
-
} else if (req.query && req.query.token) {
|
|
16
|
-
token = req.query.token;
|
|
17
|
-
}
|
|
18
|
-
return token;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getRequestResponseTime(req, res) {
|
|
22
|
-
if (!req._startAt || !res._startAt) return null;
|
|
23
|
-
return (res._startAt[ 0 ] - req._startAt[ 0 ]) * 1e3 + (res._startAt[ 1 ] - req._startAt[ 1 ]) * 1e-6;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isRequestOfMethod(req, method) {
|
|
27
|
-
const methods = Array.isArray(method) ? method : [ method ];
|
|
28
|
-
if (!req || !req.method || _.isEmpty(methods)) return false;
|
|
29
|
-
return methods.includes(req.method);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function parseRequest(req) {
|
|
33
|
-
if (!req) return { };
|
|
34
|
-
const body = req.body || { };
|
|
35
|
-
return {
|
|
36
|
-
acceptLanguage: parseRequestAcceptLanguage(req),
|
|
37
|
-
client: body.client || null,
|
|
38
|
-
clientVersion: body.applicationVersion || null,
|
|
39
|
-
ipAddress: parseRequestIpAddress(req),
|
|
40
|
-
sessionAge: body.uptime || 0,
|
|
41
|
-
sessionId: body.sessionId || null,
|
|
42
|
-
userAgent: parseRequestUserAgent(req),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function parseRequestAcceptLanguage(req) {
|
|
47
|
-
const body = req.body || { };
|
|
48
|
-
return body.language || req.header(rqh.ACCEPT_LANGUAGE);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function parseRequestIpAddress(req) {
|
|
52
|
-
const LOCALHOST_IPS = [ '127.0.0.1', '::1' ];
|
|
53
|
-
const body = req.body || { };
|
|
54
|
-
const requestIpAddress = parseIpAddress(body.ipAddress) || parseIpAddress(req.get(rqh.FORWARDED_FOR)) || parseIpAddress(req.socket.remoteAddress);
|
|
55
|
-
return LOCALHOST_IPS.includes(requestIpAddress) ? 'localhost' : requestIpAddress;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function parseRequestUserAgent(req) {
|
|
59
|
-
const body = req.body || { };
|
|
60
|
-
return body.agent || body.osVersion || req.get(rqh.USER_AGENT);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = {
|
|
64
|
-
extractToken,
|
|
65
|
-
getRequestResponseTime,
|
|
66
|
-
isRequestOfMethod,
|
|
67
|
-
parseRequest,
|
|
68
|
-
};
|
|
1
|
+
// Copyright (c) 2025-2026 by Beardon Services, Inc.
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
const enums = require('./enums');
|
|
6
|
+
const { parseIpAddress } = require('./ip_address');
|
|
7
|
+
|
|
8
|
+
const { httpRequestHeaders: rqh } = enums;
|
|
9
|
+
|
|
10
|
+
function extractToken(req) {
|
|
11
|
+
let token;
|
|
12
|
+
const authHeader = req.header(rqh.AUTHORIZATION);
|
|
13
|
+
if (authHeader && authHeader.startsWith(`${ rqh.BEARER_PREFIX } `)) {
|
|
14
|
+
token = req.header(rqh.AUTHORIZATION).split(' ')[ 1 ];
|
|
15
|
+
} else if (req.query && req.query.token) {
|
|
16
|
+
token = req.query.token;
|
|
17
|
+
}
|
|
18
|
+
return token;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getRequestResponseTime(req, res) {
|
|
22
|
+
if (!req._startAt || !res._startAt) return null;
|
|
23
|
+
return (res._startAt[ 0 ] - req._startAt[ 0 ]) * 1e3 + (res._startAt[ 1 ] - req._startAt[ 1 ]) * 1e-6;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isRequestOfMethod(req, method) {
|
|
27
|
+
const methods = Array.isArray(method) ? method : [ method ];
|
|
28
|
+
if (!req || !req.method || _.isEmpty(methods)) return false;
|
|
29
|
+
return methods.includes(req.method);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseRequest(req) {
|
|
33
|
+
if (!req) return { };
|
|
34
|
+
const body = req.body || { };
|
|
35
|
+
return {
|
|
36
|
+
acceptLanguage: parseRequestAcceptLanguage(req),
|
|
37
|
+
client: body.client || null,
|
|
38
|
+
clientVersion: body.applicationVersion || null,
|
|
39
|
+
ipAddress: parseRequestIpAddress(req),
|
|
40
|
+
sessionAge: body.uptime || 0,
|
|
41
|
+
sessionId: body.sessionId || null,
|
|
42
|
+
userAgent: parseRequestUserAgent(req),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseRequestAcceptLanguage(req) {
|
|
47
|
+
const body = req.body || { };
|
|
48
|
+
return body.language || req.header(rqh.ACCEPT_LANGUAGE);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function parseRequestIpAddress(req) {
|
|
52
|
+
const LOCALHOST_IPS = [ '127.0.0.1', '::1' ];
|
|
53
|
+
const body = req.body || { };
|
|
54
|
+
const requestIpAddress = parseIpAddress(body.ipAddress) || parseIpAddress(req.get(rqh.FORWARDED_FOR)) || parseIpAddress(req.socket.remoteAddress);
|
|
55
|
+
return LOCALHOST_IPS.includes(requestIpAddress) ? 'localhost' : requestIpAddress;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parseRequestUserAgent(req) {
|
|
59
|
+
const body = req.body || { };
|
|
60
|
+
return body.agent || body.osVersion || req.get(rqh.USER_AGENT);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
extractToken,
|
|
65
|
+
getRequestResponseTime,
|
|
66
|
+
isRequestOfMethod,
|
|
67
|
+
parseRequest,
|
|
68
|
+
};
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
// Copyright (c) 2026 by Beardon Services, Inc.
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const ansiHTML = require('ansi-html');
|
|
5
|
-
const { createTransport } = require('nodemailer');
|
|
6
|
-
const { hostname } = require('node:os');
|
|
7
|
-
const { stripVTControlCharacters } = require('node:util');
|
|
8
|
-
const Transport = require('winston-transport');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @class
|
|
12
|
-
* @extends Transport
|
|
13
|
-
*/
|
|
14
|
-
class WinstonEmailTransport extends Transport {
|
|
15
|
-
|
|
16
|
-
_messageOptions = { };
|
|
17
|
-
#useHtml = false;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @callback FilterFunction
|
|
21
|
-
* @param {Object} info
|
|
22
|
-
* @param {string} info.level
|
|
23
|
-
* @param {string} info.message
|
|
24
|
-
* @returns {boolean}
|
|
25
|
-
*
|
|
26
|
-
* @param {Object} [options={}] Options for this instance
|
|
27
|
-
* @param {Object} [options.transportOptions]
|
|
28
|
-
* @param {Object} [options.messageOptions]
|
|
29
|
-
* @param {string} [options.messageOptions.to]
|
|
30
|
-
* @param {string} [options.messageOptions.from]
|
|
31
|
-
* @param {string} [options.messageOptions.subject]
|
|
32
|
-
* @param {FilterFunction} [options.messageOptions.filter]
|
|
33
|
-
* @throws {Error} if options.messageOptions.to is empty or not set
|
|
34
|
-
*/
|
|
35
|
-
constructor(options) {
|
|
36
|
-
options = options || { };
|
|
37
|
-
const { messageOptions = { }, transportOptions = { }, ...winstonOptions } = options;
|
|
38
|
-
super(winstonOptions);
|
|
39
|
-
if (!_.isString(messageOptions.to) || !messageOptions.to.length) {
|
|
40
|
-
throw new Error('WinstonEmailTransport requires \'to\' property');
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* @member {Object} _messageOptions
|
|
44
|
-
* @member {string} _messageOptions.to
|
|
45
|
-
* @member {string} _messageOptions.from
|
|
46
|
-
* @member {string} _messageOptions.subject
|
|
47
|
-
* @member {FilterFunction} _messageOptions.filter
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
this._messageOptions = {
|
|
51
|
-
...messageOptions,
|
|
52
|
-
from: messageOptions.from ?? `winston@${ hostname() }`,
|
|
53
|
-
subject: messageOptions.subject ?? 'Winston Log',
|
|
54
|
-
filter: messageOptions.filter ?? (() => true),
|
|
55
|
-
};
|
|
56
|
-
this.name = 'WinstonEmailTransport';
|
|
57
|
-
/**
|
|
58
|
-
* @member {object}
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
this._transportOptions = transportOptions;
|
|
62
|
-
this.useHtml = winstonOptions.useHtml;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get useHtml() {
|
|
66
|
-
return this.#useHtml;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
set useHtml(useHtml) {
|
|
70
|
-
if (_.isBoolean(useHtml)) this.#useHtml = useHtml;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Core logging method exposed to Winston
|
|
75
|
-
*
|
|
76
|
-
* @callback NextFunction
|
|
77
|
-
* @returns {void}
|
|
78
|
-
*
|
|
79
|
-
* @param {Object} info
|
|
80
|
-
* @param {string} info.level
|
|
81
|
-
* @param {string} info.message
|
|
82
|
-
* @param {NextFunction} callback
|
|
83
|
-
*/
|
|
84
|
-
log(info, callback) {
|
|
85
|
-
try {
|
|
86
|
-
if (!this._messageOptions.filter(info)) {
|
|
87
|
-
setImmediate(callback);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const { level, message, ...meta } = info;
|
|
91
|
-
const _level = stripVTControlCharacters(level);
|
|
92
|
-
const _message = stripVTControlCharacters(_.isObject(message) ? JSON.stringify(message) : message);
|
|
93
|
-
/** @type {Object.<string,*>} messageOptions */
|
|
94
|
-
const { filter, ...messageOptions } = { ...this._messageOptions }
|
|
95
|
-
const subject = messageOptions.subject.replace(/{{\s*level\s*}}/g, _level).replace(/{{\s*message\s*}}/g, `${ _message }`.split('\n')[ 0 ]);
|
|
96
|
-
const content = meta[ Symbol.for('message') ];
|
|
97
|
-
const html = ansiHTML(content);
|
|
98
|
-
const text = stripVTControlCharacters(content);
|
|
99
|
-
messageOptions.subject = subject;
|
|
100
|
-
if (this.useHtml) messageOptions.html = html;
|
|
101
|
-
messageOptions.text = text;
|
|
102
|
-
const transporter = createTransport(this._transportOptions);
|
|
103
|
-
transporter.sendMail(
|
|
104
|
-
messageOptions,
|
|
105
|
-
/**
|
|
106
|
-
* @fires WinstonEmailTransport#error
|
|
107
|
-
* @fires WinstonEmailTransport#logged
|
|
108
|
-
* @param {?Error} err
|
|
109
|
-
* @param {Object} info
|
|
110
|
-
*/
|
|
111
|
-
(err, info) => {
|
|
112
|
-
setImmediate(callback);
|
|
113
|
-
if (err) {
|
|
114
|
-
this.emit('error', err);
|
|
115
|
-
} else {
|
|
116
|
-
this.emit('logged', info);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
} catch (e) {
|
|
121
|
-
console.error(e);
|
|
122
|
-
console.error('Email logging failed, moving on');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
module.exports = WinstonEmailTransport;
|
|
1
|
+
// Copyright (c) 2026 by Beardon Services, Inc.
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const ansiHTML = require('ansi-html');
|
|
5
|
+
const { createTransport } = require('nodemailer');
|
|
6
|
+
const { hostname } = require('node:os');
|
|
7
|
+
const { stripVTControlCharacters } = require('node:util');
|
|
8
|
+
const Transport = require('winston-transport');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class
|
|
12
|
+
* @extends Transport
|
|
13
|
+
*/
|
|
14
|
+
class WinstonEmailTransport extends Transport {
|
|
15
|
+
|
|
16
|
+
_messageOptions = { };
|
|
17
|
+
#useHtml = false;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @callback FilterFunction
|
|
21
|
+
* @param {Object} info
|
|
22
|
+
* @param {string} info.level
|
|
23
|
+
* @param {string} info.message
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} [options={}] Options for this instance
|
|
27
|
+
* @param {Object} [options.transportOptions]
|
|
28
|
+
* @param {Object} [options.messageOptions]
|
|
29
|
+
* @param {string} [options.messageOptions.to]
|
|
30
|
+
* @param {string} [options.messageOptions.from]
|
|
31
|
+
* @param {string} [options.messageOptions.subject]
|
|
32
|
+
* @param {FilterFunction} [options.messageOptions.filter]
|
|
33
|
+
* @throws {Error} if options.messageOptions.to is empty or not set
|
|
34
|
+
*/
|
|
35
|
+
constructor(options) {
|
|
36
|
+
options = options || { };
|
|
37
|
+
const { messageOptions = { }, transportOptions = { }, ...winstonOptions } = options;
|
|
38
|
+
super(winstonOptions);
|
|
39
|
+
if (!_.isString(messageOptions.to) || !messageOptions.to.length) {
|
|
40
|
+
throw new Error('WinstonEmailTransport requires \'to\' property');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @member {Object} _messageOptions
|
|
44
|
+
* @member {string} _messageOptions.to
|
|
45
|
+
* @member {string} _messageOptions.from
|
|
46
|
+
* @member {string} _messageOptions.subject
|
|
47
|
+
* @member {FilterFunction} _messageOptions.filter
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
this._messageOptions = {
|
|
51
|
+
...messageOptions,
|
|
52
|
+
from: messageOptions.from ?? `winston@${ hostname() }`,
|
|
53
|
+
subject: messageOptions.subject ?? 'Winston Log',
|
|
54
|
+
filter: messageOptions.filter ?? (() => true),
|
|
55
|
+
};
|
|
56
|
+
this.name = 'WinstonEmailTransport';
|
|
57
|
+
/**
|
|
58
|
+
* @member {object}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
this._transportOptions = transportOptions;
|
|
62
|
+
this.useHtml = winstonOptions.useHtml;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get useHtml() {
|
|
66
|
+
return this.#useHtml;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
set useHtml(useHtml) {
|
|
70
|
+
if (_.isBoolean(useHtml)) this.#useHtml = useHtml;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Core logging method exposed to Winston
|
|
75
|
+
*
|
|
76
|
+
* @callback NextFunction
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*
|
|
79
|
+
* @param {Object} info
|
|
80
|
+
* @param {string} info.level
|
|
81
|
+
* @param {string} info.message
|
|
82
|
+
* @param {NextFunction} callback
|
|
83
|
+
*/
|
|
84
|
+
log(info, callback) {
|
|
85
|
+
try {
|
|
86
|
+
if (!this._messageOptions.filter(info)) {
|
|
87
|
+
setImmediate(callback);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const { level, message, ...meta } = info;
|
|
91
|
+
const _level = stripVTControlCharacters(level);
|
|
92
|
+
const _message = stripVTControlCharacters(_.isObject(message) ? JSON.stringify(message) : message);
|
|
93
|
+
/** @type {Object.<string,*>} messageOptions */
|
|
94
|
+
const { filter, ...messageOptions } = { ...this._messageOptions }
|
|
95
|
+
const subject = messageOptions.subject.replace(/{{\s*level\s*}}/g, _level).replace(/{{\s*message\s*}}/g, `${ _message }`.split('\n')[ 0 ]);
|
|
96
|
+
const content = meta[ Symbol.for('message') ];
|
|
97
|
+
const html = ansiHTML(content);
|
|
98
|
+
const text = stripVTControlCharacters(content);
|
|
99
|
+
messageOptions.subject = subject;
|
|
100
|
+
if (this.useHtml) messageOptions.html = html;
|
|
101
|
+
messageOptions.text = text;
|
|
102
|
+
const transporter = createTransport(this._transportOptions);
|
|
103
|
+
transporter.sendMail(
|
|
104
|
+
messageOptions,
|
|
105
|
+
/**
|
|
106
|
+
* @fires WinstonEmailTransport#error
|
|
107
|
+
* @fires WinstonEmailTransport#logged
|
|
108
|
+
* @param {?Error} err
|
|
109
|
+
* @param {Object} info
|
|
110
|
+
*/
|
|
111
|
+
(err, info) => {
|
|
112
|
+
setImmediate(callback);
|
|
113
|
+
if (err) {
|
|
114
|
+
this.emit('error', err);
|
|
115
|
+
} else {
|
|
116
|
+
this.emit('logged', info);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.error(e);
|
|
122
|
+
console.error('Email logging failed, moving on');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = WinstonEmailTransport;
|
package/lib/typedef.js
CHANGED
|
@@ -1,33 +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
|
-
*/
|
|
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
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "zeddemore-logger",
|
|
3
|
-
"version": "2.3.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "zeddemore-logger",
|
|
3
|
+
"version": "2.3.3",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Node.js logger using Morgan and Winston for thread and caller info tracking",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/beardon/zeddemore-logger.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"email",
|
|
14
|
+
"express",
|
|
15
|
+
"ldap",
|
|
16
|
+
"logger",
|
|
17
|
+
"morgan",
|
|
18
|
+
"nodejs",
|
|
19
|
+
"nodemailer",
|
|
20
|
+
"winston"
|
|
21
|
+
],
|
|
22
|
+
"author": "Aaron Bean <aaron.bean@beardon.com> (https://beardon.com)",
|
|
23
|
+
"license": "UNLICENSED",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/beardon/zeddemore-logger/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/beardon/zeddemore-logger#readme",
|
|
28
|
+
"main": "lib/zeddemore-logger.js",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"ansi-html": "^0.0.9",
|
|
31
|
+
"chalk": "^4.1.2",
|
|
32
|
+
"lodash": "^4.18.1",
|
|
33
|
+
"luxon": "^3.7.1",
|
|
34
|
+
"morgan": "^1.11.0",
|
|
35
|
+
"nodemailer": "^9.0.3",
|
|
36
|
+
"object-sizeof": "^2.6.5",
|
|
37
|
+
"uuid": "^11.1.1",
|
|
38
|
+
"winston": "^3.19.0",
|
|
39
|
+
"winston-transport": "^4.9.0"
|
|
40
|
+
}
|
|
41
|
+
}
|