zeddemore-logger 2.2.5 → 2.2.7
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/lib/enums.js +208 -207
- package/lib/ip_address.js +10 -0
- package/lib/request.js +68 -67
- package/package.json +34 -34
package/lib/enums.js
CHANGED
|
@@ -1,207 +1,208 @@
|
|
|
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
|
-
LOG_LEVEL_DEBUG: 34, // blue
|
|
17
|
-
LOG_LEVEL_ERROR: 31, // red
|
|
18
|
-
LOG_LEVEL_HTTP: 32, // green
|
|
19
|
-
LOG_LEVEL_INFO: 32, // green
|
|
20
|
-
LOG_LEVEL_SILLY: 35, // magenta
|
|
21
|
-
LOG_LEVEL_VERBOSE: 36, // cyan
|
|
22
|
-
LOG_LEVEL_WARNING: 33, // yellow
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const chalkFormats = {
|
|
26
|
-
ANSI: 'ansi',
|
|
27
|
-
HEX: 'hex',
|
|
28
|
-
RGB: 'rgb',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const chalkLayers = {
|
|
32
|
-
BACKGROUND: 'bg',
|
|
33
|
-
FOREGROUND: 'fg',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const hexColors = {
|
|
37
|
-
BEARDON_RED: '#951A1D',
|
|
38
|
-
BLACK: '#000000',
|
|
39
|
-
CONSOLE_WHITE: '#ECECEC',
|
|
40
|
-
DB_DELETE: '#F22613',
|
|
41
|
-
DB_INSERT: '#00B16A',
|
|
42
|
-
DB_SELECT: '#1E90FF',
|
|
43
|
-
DB_TRUNCATE: '#750505',
|
|
44
|
-
DB_UPDATE: '#F9690E',
|
|
45
|
-
HTTP_CONNECT: '#FFFFFF',
|
|
46
|
-
HTTP_DELETE: '#EF968A',
|
|
47
|
-
HTTP_GET: '#67D193',
|
|
48
|
-
HTTP_HEAD: '#68D696',
|
|
49
|
-
HTTP_OPTIONS: '#E55AA8',
|
|
50
|
-
HTTP_PATCH: '#C0A8E1',
|
|
51
|
-
HTTP_POST: '#F4DA7A',
|
|
52
|
-
HTTP_PUT: '#74AEF6',
|
|
53
|
-
HTTP_TRACE: '#FFFFFF',
|
|
54
|
-
PACKAGE_ANGULARJS: '#C04737',
|
|
55
|
-
PACKAGE_AXIOS: '#6200e1',
|
|
56
|
-
PACKAGE_EXPRESS: '#F7DF1E',
|
|
57
|
-
PACKAGE_HANDLEBARS: '#F0772B',
|
|
58
|
-
PACKAGE_JIMP: '#FF0000',
|
|
59
|
-
PACKAGE_MYSQL: '#00618A',
|
|
60
|
-
PACKAGE_NODE_JS: '#689F63',
|
|
61
|
-
PACKAGE_NODEMAILER: '#29ABE2',
|
|
62
|
-
PACKAGE_PASSPORT: '#51E492',
|
|
63
|
-
PACKAGE_PDFKIT: '#DB000D',
|
|
64
|
-
PACKAGE_POSTGRESQL: '#336791',
|
|
65
|
-
PACKAGE_REDIS: '#C23936',
|
|
66
|
-
PACKAGE_SEQUELIZE: '#00AFEF',
|
|
67
|
-
PACKAGE_ZEDDEMORE: '#E2B68F',
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const httpStatusCodeGroups = {
|
|
71
|
-
INFORMATIONAL: 1,
|
|
72
|
-
SUCCESSFUL: 2,
|
|
73
|
-
REDIRECTION: 3,
|
|
74
|
-
CLIENT_ERROR: 4,
|
|
75
|
-
SERVER_ERROR: 5,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const httpMethods = {
|
|
79
|
-
GET: 'GET',
|
|
80
|
-
HEAD: 'HEAD',
|
|
81
|
-
POST: 'POST',
|
|
82
|
-
PUT: 'PUT',
|
|
83
|
-
DELETE: 'DELETE',
|
|
84
|
-
CONNECT: 'CONNECT',
|
|
85
|
-
OPTIONS: 'OPTIONS',
|
|
86
|
-
TRACE: 'TRACE',
|
|
87
|
-
PATCH: 'PATCH',
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const httpRequestHeaders = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
LOG_LEVEL_DEBUG: 34, // blue
|
|
17
|
+
LOG_LEVEL_ERROR: 31, // red
|
|
18
|
+
LOG_LEVEL_HTTP: 32, // green
|
|
19
|
+
LOG_LEVEL_INFO: 32, // green
|
|
20
|
+
LOG_LEVEL_SILLY: 35, // magenta
|
|
21
|
+
LOG_LEVEL_VERBOSE: 36, // cyan
|
|
22
|
+
LOG_LEVEL_WARNING: 33, // yellow
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const chalkFormats = {
|
|
26
|
+
ANSI: 'ansi',
|
|
27
|
+
HEX: 'hex',
|
|
28
|
+
RGB: 'rgb',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const chalkLayers = {
|
|
32
|
+
BACKGROUND: 'bg',
|
|
33
|
+
FOREGROUND: 'fg',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const hexColors = {
|
|
37
|
+
BEARDON_RED: '#951A1D',
|
|
38
|
+
BLACK: '#000000',
|
|
39
|
+
CONSOLE_WHITE: '#ECECEC',
|
|
40
|
+
DB_DELETE: '#F22613',
|
|
41
|
+
DB_INSERT: '#00B16A',
|
|
42
|
+
DB_SELECT: '#1E90FF',
|
|
43
|
+
DB_TRUNCATE: '#750505',
|
|
44
|
+
DB_UPDATE: '#F9690E',
|
|
45
|
+
HTTP_CONNECT: '#FFFFFF',
|
|
46
|
+
HTTP_DELETE: '#EF968A',
|
|
47
|
+
HTTP_GET: '#67D193',
|
|
48
|
+
HTTP_HEAD: '#68D696',
|
|
49
|
+
HTTP_OPTIONS: '#E55AA8',
|
|
50
|
+
HTTP_PATCH: '#C0A8E1',
|
|
51
|
+
HTTP_POST: '#F4DA7A',
|
|
52
|
+
HTTP_PUT: '#74AEF6',
|
|
53
|
+
HTTP_TRACE: '#FFFFFF',
|
|
54
|
+
PACKAGE_ANGULARJS: '#C04737',
|
|
55
|
+
PACKAGE_AXIOS: '#6200e1',
|
|
56
|
+
PACKAGE_EXPRESS: '#F7DF1E',
|
|
57
|
+
PACKAGE_HANDLEBARS: '#F0772B',
|
|
58
|
+
PACKAGE_JIMP: '#FF0000',
|
|
59
|
+
PACKAGE_MYSQL: '#00618A',
|
|
60
|
+
PACKAGE_NODE_JS: '#689F63',
|
|
61
|
+
PACKAGE_NODEMAILER: '#29ABE2',
|
|
62
|
+
PACKAGE_PASSPORT: '#51E492',
|
|
63
|
+
PACKAGE_PDFKIT: '#DB000D',
|
|
64
|
+
PACKAGE_POSTGRESQL: '#336791',
|
|
65
|
+
PACKAGE_REDIS: '#C23936',
|
|
66
|
+
PACKAGE_SEQUELIZE: '#00AFEF',
|
|
67
|
+
PACKAGE_ZEDDEMORE: '#E2B68F',
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const httpStatusCodeGroups = {
|
|
71
|
+
INFORMATIONAL: 1,
|
|
72
|
+
SUCCESSFUL: 2,
|
|
73
|
+
REDIRECTION: 3,
|
|
74
|
+
CLIENT_ERROR: 4,
|
|
75
|
+
SERVER_ERROR: 5,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const httpMethods = {
|
|
79
|
+
GET: 'GET',
|
|
80
|
+
HEAD: 'HEAD',
|
|
81
|
+
POST: 'POST',
|
|
82
|
+
PUT: 'PUT',
|
|
83
|
+
DELETE: 'DELETE',
|
|
84
|
+
CONNECT: 'CONNECT',
|
|
85
|
+
OPTIONS: 'OPTIONS',
|
|
86
|
+
TRACE: 'TRACE',
|
|
87
|
+
PATCH: 'PATCH',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const httpRequestHeaders = {
|
|
91
|
+
ACCEPT_LANGUAGE: 'Accept-Language',
|
|
92
|
+
ALLOW: 'Allow',
|
|
93
|
+
APP_VERSION: 'App-Version',
|
|
94
|
+
AUTHORIZATION: 'Authorization',
|
|
95
|
+
BEARER_PREFIX: 'Bearer',
|
|
96
|
+
FORWARDED_FOR: 'X-Forwarded-For',
|
|
97
|
+
REQUEST_ID: 'X-Request-Id',
|
|
98
|
+
USER_AGENT: 'User-Agent',
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const httpResponseHeaders = {
|
|
102
|
+
CONTENT_LENGTH: 'Content-Length',
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const logLevelTypes = {
|
|
106
|
+
CONSOLE: 'console',
|
|
107
|
+
EMAIL: 'email',
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const morganFormats = {
|
|
111
|
+
COMBINED: 'combined',
|
|
112
|
+
COMMON: 'common',
|
|
113
|
+
DEV: 'dev',
|
|
114
|
+
SHORT: 'short',
|
|
115
|
+
TINY: 'tiny',
|
|
116
|
+
ZEDDEMORE: 'zeddemore', // added for `zeddemore-logger`
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const morganFormatTokens = {
|
|
120
|
+
CONTENT_LENGTH_FORMAT: 'content-length-format', // added for `zeddemore-logger`
|
|
121
|
+
DATE: 'date', // :date[format]
|
|
122
|
+
DECODED_URL: 'decoded-url', // added for `zeddemore-logger`
|
|
123
|
+
HTTP_VERSION: 'http-version',
|
|
124
|
+
METHOD: 'method',
|
|
125
|
+
REFERRER: 'referrer',
|
|
126
|
+
REMOTE_ADDR: 'remote-addr',
|
|
127
|
+
REMOTE_USER: 'remote-user',
|
|
128
|
+
REQ: 'req', // :req[header]
|
|
129
|
+
RES: 'res', // :res[header]
|
|
130
|
+
RESPONSE_TIME: 'response-time', // :response-time[digits]
|
|
131
|
+
RESPONSE_TIME_FORMAT: 'response-time-format', // added for `zeddemore-logger`
|
|
132
|
+
STATUS: 'status',
|
|
133
|
+
STATUS_COLORED: 'status-colored', // added for `zeddemore-logger`
|
|
134
|
+
TOTAL_TIME: 'total-time', // :total-time[digits]
|
|
135
|
+
URL: 'url',
|
|
136
|
+
USER_AGENT: 'user-agent',
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const winstonFormats = {
|
|
140
|
+
COLORIZE: 'colorize',
|
|
141
|
+
JSON: 'json',
|
|
142
|
+
METADATA: 'metadata',
|
|
143
|
+
PRETTY_PRINT: 'pretty_print',
|
|
144
|
+
SIMPLE: 'simple',
|
|
145
|
+
SPLAT: 'splat',
|
|
146
|
+
TIMESTAMP: 'timestamp',
|
|
147
|
+
ZEDDEMORE_INFO_MUTATION: 'zeddemore_info_mutation',
|
|
148
|
+
ZEDDEMORE_LABEL: 'zeddemore_label',
|
|
149
|
+
ZEDDEMORE_PRINTF: 'zeddemore_printf',
|
|
150
|
+
ZEDDEMORE_TIMESTAMP: 'zeddemore_timestamp',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const winstonLogLevelNames = {
|
|
154
|
+
ERROR: 'error',
|
|
155
|
+
WARNING: 'warn',
|
|
156
|
+
INFO: 'info',
|
|
157
|
+
HTTP: 'http',
|
|
158
|
+
VERBOSE: 'verbose',
|
|
159
|
+
DEBUG: 'debug',
|
|
160
|
+
SILLY: 'silly',
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// using NPM logging levels
|
|
164
|
+
const winstonLogLevels = {
|
|
165
|
+
ERROR: 0,
|
|
166
|
+
WARNING: 1,
|
|
167
|
+
INFO: 2,
|
|
168
|
+
HTTP: 3,
|
|
169
|
+
VERBOSE: 4,
|
|
170
|
+
DEBUG: 5,
|
|
171
|
+
SILLY: 6,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const winstonTransports = {
|
|
175
|
+
CONSOLE: 'console',
|
|
176
|
+
EMAIL: 'email',
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const zeddemoreLogLevelCaptions = {
|
|
180
|
+
DEFAULT: 'Default',
|
|
181
|
+
ERROR: 'Error',
|
|
182
|
+
WARNING: 'Warning',
|
|
183
|
+
INFO: 'Info',
|
|
184
|
+
HTTP: 'HTTP',
|
|
185
|
+
VERBOSE: 'Verbose',
|
|
186
|
+
DEBUG: 'Debug',
|
|
187
|
+
SILLY: 'Silly',
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
module.exports = {
|
|
191
|
+
doesEnumInclude,
|
|
192
|
+
ansiColors,
|
|
193
|
+
chalkFormats,
|
|
194
|
+
chalkLayers,
|
|
195
|
+
hexColors,
|
|
196
|
+
httpStatusCodeGroups,
|
|
197
|
+
httpMethods,
|
|
198
|
+
httpRequestHeaders,
|
|
199
|
+
httpResponseHeaders,
|
|
200
|
+
logLevelTypes,
|
|
201
|
+
morganFormats,
|
|
202
|
+
morganFormatTokens,
|
|
203
|
+
winstonFormats,
|
|
204
|
+
winstonLogLevelNames,
|
|
205
|
+
winstonLogLevels,
|
|
206
|
+
winstonTransports,
|
|
207
|
+
zeddemoreLogLevelCaptions,
|
|
208
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
|
|
3
|
+
function parseIpAddress(ipAddress) {
|
|
4
|
+
const ipChain = (_.isString(ipAddress) && !!ipAddress.trim().length) ? ipAddress.split(',').map((ip) => ip.trim()) : [ ];
|
|
5
|
+
return !!ipChain.length ? ipChain[ 0 ] : null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
parseIpAddress,
|
|
10
|
+
};
|
package/lib/request.js
CHANGED
|
@@ -1,67 +1,68 @@
|
|
|
1
|
-
// Copyright (c) 2025 by Beardon Services, Inc.
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
const enums = require('./enums');
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const LOCALHOST_IPS = [ '127.0.0.1', '::1' ];
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "zeddemore-logger",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "Node.js Express logger using Morgan and Winston for thread and caller info tracking",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/beardon/zeddemore-logger.git"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"express",
|
|
11
|
-
"logger",
|
|
12
|
-
"morgan",
|
|
13
|
-
"winston"
|
|
14
|
-
],
|
|
15
|
-
"author": "Aaron Bean <aaron.bean@beardon.com> (https://beardon.com)",
|
|
16
|
-
"license": "UNLICENSED",
|
|
17
|
-
"bugs": {
|
|
18
|
-
"url": "https://github.com/beardon/zeddemore-logger/issues"
|
|
19
|
-
},
|
|
20
|
-
"homepage": "https://github.com/beardon/zeddemore-logger#readme",
|
|
21
|
-
"main": "lib/zeddemore-logger.js",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"ansi-html": "^0.0.9",
|
|
24
|
-
"chalk": "^4.1.2",
|
|
25
|
-
"lodash": "^4.18.1",
|
|
26
|
-
"luxon": "^3.7.1",
|
|
27
|
-
"morgan": "^1.10.1",
|
|
28
|
-
"nodemailer": "^8.0.5",
|
|
29
|
-
"object-sizeof": "^2.6.5",
|
|
30
|
-
"uuid": "^10.0.0",
|
|
31
|
-
"winston": "^3.17.0",
|
|
32
|
-
"winston-transport": "^4.9.0"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "zeddemore-logger",
|
|
3
|
+
"version": "2.2.7",
|
|
4
|
+
"description": "Node.js Express logger using Morgan and Winston for thread and caller info tracking",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/beardon/zeddemore-logger.git"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"express",
|
|
11
|
+
"logger",
|
|
12
|
+
"morgan",
|
|
13
|
+
"winston"
|
|
14
|
+
],
|
|
15
|
+
"author": "Aaron Bean <aaron.bean@beardon.com> (https://beardon.com)",
|
|
16
|
+
"license": "UNLICENSED",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/beardon/zeddemore-logger/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/beardon/zeddemore-logger#readme",
|
|
21
|
+
"main": "lib/zeddemore-logger.js",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"ansi-html": "^0.0.9",
|
|
24
|
+
"chalk": "^4.1.2",
|
|
25
|
+
"lodash": "^4.18.1",
|
|
26
|
+
"luxon": "^3.7.1",
|
|
27
|
+
"morgan": "^1.10.1",
|
|
28
|
+
"nodemailer": "^8.0.5",
|
|
29
|
+
"object-sizeof": "^2.6.5",
|
|
30
|
+
"uuid": "^10.0.0",
|
|
31
|
+
"winston": "^3.17.0",
|
|
32
|
+
"winston-transport": "^4.9.0"
|
|
33
|
+
}
|
|
34
|
+
}
|