winston-middleware 1.1.0 → 1.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/.travis.yml +3 -2
- package/AUTHORS +1 -0
- package/Readme.md +69 -30
- package/index.js +60 -44
- package/package.json +9 -8
- package/test/test.js +704 -453
package/.travis.yml
CHANGED
package/AUTHORS
CHANGED
package/Readme.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# winston-middleware
|
|
2
|
-
[](http://travis-ci.org/bithavoc/winston-middleware)
|
|
2
|
+
[](https://www.npmjs.com/package/winston-middleware) [](http://travis-ci.org/bithavoc/winston-middleware)
|
|
3
3
|
|
|
4
4
|
> [winston](https://github.com/flatiron/winston) middleware for express.js
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
|
8
|
-
Newcomers should start with the latest branch which makes use of winston 1.x.x:
|
|
8
|
+
Newcomers should start with the latest branch which makes use of winston 1.x.x and supports node >= 0.10:
|
|
9
9
|
|
|
10
10
|
npm install winston-middleware
|
|
11
11
|
|
|
12
12
|
If you're already using winston-middleware, and want to stick with the stable version based on winston 0.9.x, you should instead do:
|
|
13
13
|
|
|
14
|
-
npm install winston-middleware@0.
|
|
14
|
+
npm install winston-middleware@0.x.x --save
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
17
17
|
|
|
@@ -39,64 +39,91 @@ var winston = require('winston'),
|
|
|
39
39
|
expressWinston = require('winston-middleware');
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### Request Logging
|
|
43
43
|
|
|
44
|
-
Use `expressWinston.
|
|
44
|
+
Use `expressWinston.logger(options)` to create a middleware to log your HTTP requests.
|
|
45
45
|
|
|
46
46
|
``` js
|
|
47
47
|
var router = require('./my-express-router');
|
|
48
48
|
|
|
49
|
-
app.use(
|
|
50
|
-
app.use(expressWinston.errorLogger({
|
|
49
|
+
app.use(expressWinston.logger({
|
|
51
50
|
transports: [
|
|
52
51
|
new winston.transports.Console({
|
|
53
52
|
json: true,
|
|
54
53
|
colorize: true
|
|
55
54
|
})
|
|
56
|
-
]
|
|
55
|
+
],
|
|
56
|
+
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
|
|
57
|
+
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
|
|
58
|
+
expressFormat: true, // Use the default Express/morgan request formatting, with the same colors. Enabling this will override any msg and colorStatus if true. Will only output colors on transports with colorize set to true
|
|
59
|
+
colorStatus: true, // Color the status code, using the Express/morgan color palette (default green, 3XX cyan, 4XX yellow, 5XX red). Will not be recognized if expressFormat is true
|
|
60
|
+
ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
|
|
57
61
|
}));
|
|
58
|
-
```
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
app.use(router); // notice how the router goes after the logger.
|
|
64
|
+
```
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
#### Options
|
|
63
67
|
|
|
64
68
|
``` js
|
|
65
69
|
transports: [<WinstonTransport>], // list of all winston transports instances to use.
|
|
66
|
-
winstonInstance: <WinstonLogger>, // a winston logger instance. If this is provided the transports option is ignored
|
|
70
|
+
winstonInstance: <WinstonLogger>, // a winston logger instance. If this is provided the transports option is ignored.
|
|
67
71
|
level: String, // log level to use, the default is "info".
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
msg: String // customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}", "HTTP {{req.method}} {{req.url}}".
|
|
73
|
+
expressFormat: Boolean, // Use the default Express/morgan request formatting, with the same colors. Enabling this will override any msg and colorStatus if true. Will only output colors on transports with colorize set to true
|
|
74
|
+
colorStatus: Boolean, // Color the status code, using the Express/morgan color palette (default green, 3XX cyan, 4XX yellow, 5XX red). Will not be recognized if expressFormat is true
|
|
75
|
+
meta: Boolean, // control whether you want to log the meta data about the request (default to true).
|
|
76
|
+
baseMeta: Object, // default meta data to be added to log, this will be merged with the meta data.
|
|
77
|
+
metaField: String, // if defined, the meta data will be added in this field instead of the meta root object.
|
|
78
|
+
statusLevels: Boolean or Object // different HTTP status codes caused log messages to be logged at different levels (info/warn/error), the default is false. Use an object to control the levels various status codes are logged at.
|
|
79
|
+
ignoreRoute: function (req, res) { return false; } // allows to skip some log messages based on request and/or response.
|
|
80
|
+
skip: function(req, res) { return false; } // function to determine if logging is skipped, defaults to false.
|
|
81
|
+
requestFilter: function (req, propName) { return req[propName]; } // A function to filter/return request values, defaults to returning all values allowed by whitelist. If the function returns undefined, the key/value will not be included in the meta.
|
|
82
|
+
responseFilter: function (res, propName) { return res[propName]; } // A function to filter/return response values, defaults to returning all values allowed by whitelist. If the function returns undefined, the key/value will not be included in the meta.
|
|
83
|
+
requestWhitelist: [String] // Array of request properties to log. Overrides global requestWhitelist for this instance
|
|
84
|
+
responseWhitelist: [String] // Array of response properties to log. Overrides global responseWhitelist for this instance
|
|
85
|
+
bodyWhitelist: [String] // Array of body properties to log. Overrides global bodyWhitelist for this instance
|
|
86
|
+
bodyBlacklist: [String] // Array of body properties to omit from logs. Overrides global bodyBlacklist for this instance
|
|
87
|
+
ignoredRoutes: [String] // Array of paths to ignore/skip logging. Overrides global ignoredRoutes for this instance
|
|
71
88
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Alternatively, if you're using a winston logger instance elsewhere and have already set up levels and transports, pass the instance into expressWinston with the `winstonInstance` option. The `transports` option is then ignored.
|
|
89
|
+
```
|
|
75
90
|
|
|
76
|
-
###
|
|
91
|
+
### Error Logging
|
|
77
92
|
|
|
78
|
-
Use `expressWinston.
|
|
93
|
+
Use `expressWinston.errorLogger(options)` to create a middleware that log the errors of the pipeline.
|
|
79
94
|
|
|
80
95
|
``` js
|
|
81
96
|
var router = require('./my-express-router');
|
|
82
97
|
|
|
83
|
-
app.use(
|
|
98
|
+
app.use(router); // notice how the router goes first.
|
|
99
|
+
app.use(expressWinston.errorLogger({
|
|
84
100
|
transports: [
|
|
85
101
|
new winston.transports.Console({
|
|
86
102
|
json: true,
|
|
87
103
|
colorize: true
|
|
88
104
|
})
|
|
89
|
-
]
|
|
90
|
-
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
|
|
91
|
-
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
|
|
92
|
-
expressFormat: true, // Use the default Express/morgan request formatting, with the same colors. Enabling this will override any msg and colorStatus if true. Will only output colors on transports with colorize set to true
|
|
93
|
-
colorStatus: true, // Color the status code, using the Express/morgan color palette (default green, 3XX cyan, 4XX yellow, 5XX red). Will not be recognized if expressFormat is true
|
|
94
|
-
ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
|
|
105
|
+
]
|
|
95
106
|
}));
|
|
107
|
+
```
|
|
96
108
|
|
|
97
|
-
|
|
109
|
+
The logger needs to be added AFTER the express router(`app.router)`) and BEFORE any of your custom error handlers(`express.handler`). Since winston-middleware will just log the errors and not __handle__ them, you can still use your custom error handler like `express.handler`, just be sure to put the logger before any of your handlers.
|
|
110
|
+
|
|
111
|
+
#### Options
|
|
112
|
+
|
|
113
|
+
``` js
|
|
114
|
+
transports: [<WinstonTransport>], // list of all winston transports instances to use.
|
|
115
|
+
winstonInstance: <WinstonLogger>, // a winston logger instance. If this is provided the transports option is ignored
|
|
116
|
+
msg: String // customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}", "HTTP {{req.method}} {{req.url}}".
|
|
117
|
+
baseMeta: Object, // default meta data to be added to log, this will be merged with the error data.
|
|
118
|
+
metaField: String, // if defined, the meta data will be added in this field instead of the meta root object.
|
|
119
|
+
requestFilter: function (req, propName) { return req[propName]; } // A function to filter/return request values, defaults to returning all values allowed by whitelist. If the function returns undefined, the key/value will not be included in the meta.
|
|
120
|
+
requestWhitelist: [String] // Array of request properties to log. Overrides global requestWhitelist for this instance
|
|
98
121
|
```
|
|
99
122
|
|
|
123
|
+
To use winston's existing transports, set `transports` to the values (as in key-value) of the `winston.default.transports` object. This may be done, for example, by using underscorejs: `transports: _.values(winston.default.transports)`.
|
|
124
|
+
|
|
125
|
+
Alternatively, if you're using a winston logger instance elsewhere and have already set up levels and transports, pass the instance into expressWinston with the `winstonInstance` option. The `transports` option is then ignored.
|
|
126
|
+
|
|
100
127
|
## Examples
|
|
101
128
|
|
|
102
129
|
``` js
|
|
@@ -346,6 +373,17 @@ If both `req._bodyWhitelist.body` and `req._bodyBlacklist.body` are set the resu
|
|
|
346
373
|
excluding any black listed ones. In the above example, only 'email' and 'age' would be included.
|
|
347
374
|
|
|
348
375
|
|
|
376
|
+
## Custom Status Levels
|
|
377
|
+
|
|
378
|
+
If you set statusLevels to true winston-middleware will log sub 400 responses at info level, sub 500 responses as warnings and 500+ responses as errors. To change these levels specify an object as follows
|
|
379
|
+
```json
|
|
380
|
+
"statusLevels": {
|
|
381
|
+
"success": "debug",
|
|
382
|
+
"warn": "debug",
|
|
383
|
+
"error": "info"
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
349
387
|
## Tests
|
|
350
388
|
|
|
351
389
|
Run the basic Mocha tests:
|
|
@@ -354,11 +392,11 @@ Run the basic Mocha tests:
|
|
|
354
392
|
|
|
355
393
|
Run the Travis-CI tests (which will fail with < 100% coverage):
|
|
356
394
|
|
|
357
|
-
npm test-travis
|
|
395
|
+
npm run test-travis
|
|
358
396
|
|
|
359
397
|
Generate the `coverage.html` coverage report:
|
|
360
398
|
|
|
361
|
-
npm test-coverage
|
|
399
|
+
npm run test-coverage
|
|
362
400
|
|
|
363
401
|
## Issues and Collaboration
|
|
364
402
|
|
|
@@ -369,6 +407,7 @@ If you ran into any problems, please use the project [Issues section](https://gi
|
|
|
369
407
|
* [Johan Hernandez](https://github.com/bithavoc) (https://github.com/bithavoc)
|
|
370
408
|
* [Lars Jacob](https://github.com/jaclar) (https://github.com/jaclar)
|
|
371
409
|
* [Jonathan Lomas](https://github.com/floatingLomas) (https://github.com/floatingLomas)
|
|
410
|
+
* [Ross Brandes](https://github.com/rosston) (https://github.com/rosston)
|
|
372
411
|
|
|
373
412
|
Also see AUTHORS file, add yourself if you are missing.
|
|
374
413
|
|
package/index.js
CHANGED
|
@@ -34,34 +34,34 @@ delete require.cache[require.resolve('underscore')];
|
|
|
34
34
|
* TODO: Include 'body' and get the defaultRequestFilter to filter the inner properties like 'password' or 'password_confirmation', etc. Pull requests anyone?
|
|
35
35
|
* @type {Array}
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
exports.requestWhitelist = ['url', 'headers', 'method', 'httpVersion', 'originalUrl', 'query'];
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* A default list of properties in the request body that are allowed to be logged.
|
|
41
41
|
* This will normally be empty here, since it should be done at the route level.
|
|
42
42
|
* @type {Array}
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
exports.bodyWhitelist = [];
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* A default list of properties in the request body that are not allowed to be logged.
|
|
48
48
|
* @type {Array}
|
|
49
49
|
*/
|
|
50
|
-
|
|
50
|
+
exports.bodyBlacklist = [];
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* A default list of properties in the response object that are allowed to be logged.
|
|
54
54
|
* These properties will be safely included in the meta of the log.
|
|
55
55
|
* @type {Array}
|
|
56
56
|
*/
|
|
57
|
-
|
|
57
|
+
exports.responseWhitelist = ['statusCode'];
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* A list of request routes that will be skipped instead of being logged. This would be useful if routes for health checks or pings would otherwise pollute
|
|
61
61
|
* your log files.
|
|
62
62
|
* @type {Array}
|
|
63
63
|
*/
|
|
64
|
-
|
|
64
|
+
exports.ignoredRoutes = [];
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* A default function to filter the properties of the req object.
|
|
@@ -69,7 +69,7 @@ var ignoredRoutes = [];
|
|
|
69
69
|
* @param propName
|
|
70
70
|
* @return {*}
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
exports.defaultRequestFilter = function (req, propName) {
|
|
73
73
|
return req[propName];
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -79,7 +79,7 @@ var defaultRequestFilter = function (req, propName) {
|
|
|
79
79
|
* @param propName
|
|
80
80
|
* @return {*}
|
|
81
81
|
*/
|
|
82
|
-
|
|
82
|
+
exports.defaultResponseFilter = function (res, propName) {
|
|
83
83
|
return res[propName];
|
|
84
84
|
};
|
|
85
85
|
|
|
@@ -87,7 +87,7 @@ var defaultResponseFilter = function (res, propName) {
|
|
|
87
87
|
* A default function to decide whether skip logging of particular request. Doesn't skip anything (i.e. log all requests).
|
|
88
88
|
* @return always false
|
|
89
89
|
*/
|
|
90
|
-
|
|
90
|
+
exports.defaultSkip = function() {
|
|
91
91
|
return false;
|
|
92
92
|
};
|
|
93
93
|
|
|
@@ -114,13 +114,16 @@ function filterObject(originalObj, whiteList, initialFilter) {
|
|
|
114
114
|
//
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
function errorLogger(options) {
|
|
117
|
+
exports.errorLogger = function errorLogger(options) {
|
|
118
118
|
|
|
119
119
|
ensureValidOptions(options);
|
|
120
120
|
|
|
121
|
-
options.
|
|
121
|
+
options.requestWhitelist = options.requestWhitelist || exports.requestWhitelist;
|
|
122
|
+
options.requestFilter = options.requestFilter || exports.defaultRequestFilter;
|
|
122
123
|
options.winstonInstance = options.winstonInstance || (new winston.Logger ({ transports: options.transports }));
|
|
123
124
|
options.msg = options.msg || 'middlewareError';
|
|
125
|
+
options.baseMeta = options.baseMeta || {};
|
|
126
|
+
options.metaField = options.metaField || null;
|
|
124
127
|
|
|
125
128
|
// Using mustache style templating
|
|
126
129
|
var template = _.template(options.msg, null, {
|
|
@@ -131,14 +134,22 @@ function errorLogger(options) {
|
|
|
131
134
|
|
|
132
135
|
// Let winston gather all the error data.
|
|
133
136
|
var exceptionMeta = winston.exception.getAllInfo(err);
|
|
134
|
-
exceptionMeta.req = filterObject(req, requestWhitelist, options.requestFilter);
|
|
137
|
+
exceptionMeta.req = filterObject(req, options.requestWhitelist, options.requestFilter);
|
|
138
|
+
|
|
139
|
+
if (options.metaField) {
|
|
140
|
+
var newMeta = {};
|
|
141
|
+
newMeta[options.metaField] = exceptionMeta;
|
|
142
|
+
exceptionMeta = newMeta;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
exceptionMeta = _.extend(exceptionMeta, options.baseMeta);
|
|
135
146
|
|
|
136
147
|
// This is fire and forget, we don't want logging to hold up the request so don't wait for the callback
|
|
137
148
|
options.winstonInstance.log('error', template({err: err, req: req, res: res}), exceptionMeta);
|
|
138
149
|
|
|
139
150
|
next(err);
|
|
140
151
|
};
|
|
141
|
-
}
|
|
152
|
+
};
|
|
142
153
|
|
|
143
154
|
//
|
|
144
155
|
// ### function logger(options)
|
|
@@ -146,21 +157,28 @@ function errorLogger(options) {
|
|
|
146
157
|
//
|
|
147
158
|
|
|
148
159
|
|
|
149
|
-
function logger(options) {
|
|
160
|
+
exports.logger = function logger(options) {
|
|
150
161
|
|
|
151
162
|
ensureValidOptions(options);
|
|
152
163
|
ensureValidLoggerOptions(options);
|
|
153
164
|
|
|
154
|
-
options.
|
|
155
|
-
options.
|
|
165
|
+
options.requestWhitelist = options.requestWhitelist || exports.requestWhitelist;
|
|
166
|
+
options.bodyWhitelist = options.bodyWhitelist || exports.bodyWhitelist;
|
|
167
|
+
options.bodyBlacklist = options.bodyBlacklist || exports.bodyBlacklist;
|
|
168
|
+
options.responseWhitelist = options.responseWhitelist || exports.responseWhitelist;
|
|
169
|
+
options.requestFilter = options.requestFilter || exports.defaultRequestFilter;
|
|
170
|
+
options.responseFilter = options.responseFilter || exports.defaultResponseFilter;
|
|
171
|
+
options.ignoredRoutes = options.ignoredRoutes || exports.ignoredRoutes;
|
|
156
172
|
options.winstonInstance = options.winstonInstance || (new winston.Logger ({ transports: options.transports }));
|
|
157
173
|
options.level = options.level || "info";
|
|
158
174
|
options.statusLevels = options.statusLevels || false;
|
|
159
175
|
options.msg = options.msg || "HTTP {{req.method}} {{req.url}}";
|
|
176
|
+
options.baseMeta = options.baseMeta || {};
|
|
177
|
+
options.metaField = options.metaField || null;
|
|
160
178
|
options.colorStatus = options.colorStatus || false;
|
|
161
179
|
options.expressFormat = options.expressFormat || false;
|
|
162
180
|
options.ignoreRoute = options.ignoreRoute || function () { return false; };
|
|
163
|
-
options.skip = options.skip || defaultSkip;
|
|
181
|
+
options.skip = options.skip || exports.defaultSkip;
|
|
164
182
|
|
|
165
183
|
// Using mustache style templating
|
|
166
184
|
var template = _.template(options.msg, null, {
|
|
@@ -169,7 +187,7 @@ function logger(options) {
|
|
|
169
187
|
|
|
170
188
|
return function (req, res, next) {
|
|
171
189
|
var currentUrl = req.originalUrl || req.url;
|
|
172
|
-
if (currentUrl && _.contains(ignoredRoutes, currentUrl)) return next();
|
|
190
|
+
if (currentUrl && _.contains(options.ignoredRoutes, currentUrl)) return next();
|
|
173
191
|
if (options.ignoreRoute(req, res)) return next();
|
|
174
192
|
|
|
175
193
|
req._startTime = (new Date);
|
|
@@ -195,9 +213,9 @@ function logger(options) {
|
|
|
195
213
|
req.url = req.originalUrl || req.url;
|
|
196
214
|
|
|
197
215
|
if (options.statusLevels) {
|
|
198
|
-
if (res.statusCode >= 100) { options.level = "info"; }
|
|
199
|
-
if (res.statusCode >= 400) { options.level = "warn"; }
|
|
200
|
-
if (res.statusCode >= 500) { options.level = "error"; }
|
|
216
|
+
if (res.statusCode >= 100) { options.level = options.statusLevels.success || "info"; }
|
|
217
|
+
if (res.statusCode >= 400) { options.level = options.statusLevels.warn || "warn"; }
|
|
218
|
+
if (res.statusCode >= 500) { options.level = options.statusLevels.error || "error"; }
|
|
201
219
|
};
|
|
202
220
|
|
|
203
221
|
if (options.colorStatus || options.expressFormat) {
|
|
@@ -212,27 +230,27 @@ function logger(options) {
|
|
|
212
230
|
var meta = {};
|
|
213
231
|
|
|
214
232
|
if(options.meta !== false) {
|
|
215
|
-
var
|
|
233
|
+
var logData = {};
|
|
216
234
|
|
|
217
|
-
requestWhitelist = requestWhitelist.concat(req._routeWhitelists.req || []);
|
|
218
|
-
responseWhitelist = responseWhitelist.concat(req._routeWhitelists.res || []);
|
|
235
|
+
var requestWhitelist = options.requestWhitelist.concat(req._routeWhitelists.req || []);
|
|
236
|
+
var responseWhitelist = options.responseWhitelist.concat(req._routeWhitelists.res || []);
|
|
219
237
|
|
|
220
|
-
|
|
238
|
+
logData.res = res;
|
|
221
239
|
|
|
222
240
|
if (_.contains(responseWhitelist, 'body')) {
|
|
223
241
|
if (chunk) {
|
|
224
242
|
var isJson = (res._headers && res._headers['content-type']
|
|
225
243
|
&& res._headers['content-type'].indexOf('json') >= 0);
|
|
226
244
|
|
|
227
|
-
|
|
245
|
+
logData.res.body = isJson ? JSON.parse(chunk) : chunk.toString();
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
248
|
|
|
231
|
-
|
|
232
|
-
|
|
249
|
+
logData.req = filterObject(req, requestWhitelist, options.requestFilter);
|
|
250
|
+
logData.res = filterObject(res, responseWhitelist, options.responseFilter);
|
|
233
251
|
|
|
234
|
-
bodyWhitelist = req._routeWhitelists.body || [];
|
|
235
|
-
blacklist = _.union(bodyBlacklist, (req._routeBlacklists.body || []));
|
|
252
|
+
var bodyWhitelist = _.union(options.bodyWhitelist, (req._routeWhitelists.body || []));
|
|
253
|
+
var blacklist = _.union(options.bodyBlacklist, (req._routeBlacklists.body || []));
|
|
236
254
|
|
|
237
255
|
var filteredBody = null;
|
|
238
256
|
|
|
@@ -244,12 +262,21 @@ function logger(options) {
|
|
|
244
262
|
filteredBody = filterObject(req.body, bodyWhitelist, options.requestFilter);
|
|
245
263
|
}
|
|
246
264
|
}
|
|
247
|
-
|
|
248
|
-
if (filteredBody) meta.req.body = filteredBody;
|
|
249
265
|
|
|
250
|
-
|
|
266
|
+
if (filteredBody) logData.req.body = filteredBody;
|
|
267
|
+
|
|
268
|
+
logData.responseTime = res.responseTime;
|
|
269
|
+
|
|
270
|
+
if (options.metaField) {
|
|
271
|
+
var newMeta = {}
|
|
272
|
+
newMeta[options.metaField] = logData;
|
|
273
|
+
logData = newMeta;
|
|
274
|
+
}
|
|
275
|
+
meta = _.extend(meta, logData);
|
|
251
276
|
}
|
|
252
277
|
|
|
278
|
+
meta = _.extend(meta, options.baseMeta);
|
|
279
|
+
|
|
253
280
|
if(options.expressFormat) {
|
|
254
281
|
var msg = chalk.grey(req.method + " " + req.url || req.url)
|
|
255
282
|
+ " " + chalk[statusColor](res.statusCode)
|
|
@@ -265,7 +292,7 @@ function logger(options) {
|
|
|
265
292
|
|
|
266
293
|
next();
|
|
267
294
|
};
|
|
268
|
-
}
|
|
295
|
+
};
|
|
269
296
|
|
|
270
297
|
function ensureValidOptions(options) {
|
|
271
298
|
if(!options) throw new Error("options are required by winston-middleware middleware");
|
|
@@ -278,14 +305,3 @@ function ensureValidLoggerOptions(options) {
|
|
|
278
305
|
throw new Error("`ignoreRoute` winston-middleware option should be a function");
|
|
279
306
|
}
|
|
280
307
|
}
|
|
281
|
-
|
|
282
|
-
module.exports.errorLogger = errorLogger;
|
|
283
|
-
module.exports.logger = logger;
|
|
284
|
-
module.exports.requestWhitelist = requestWhitelist;
|
|
285
|
-
module.exports.bodyWhitelist = bodyWhitelist;
|
|
286
|
-
module.exports.bodyBlacklist = bodyBlacklist;
|
|
287
|
-
module.exports.responseWhitelist = responseWhitelist;
|
|
288
|
-
module.exports.defaultRequestFilter = defaultRequestFilter;
|
|
289
|
-
module.exports.defaultResponseFilter = defaultResponseFilter;
|
|
290
|
-
module.exports.defaultSkip = defaultSkip;
|
|
291
|
-
module.exports.ignoredRoutes = ignoredRoutes;
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"middleware",
|
|
18
18
|
"colors"
|
|
19
19
|
],
|
|
20
|
-
"version": "1.
|
|
20
|
+
"version": "1.3.0",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "https://github.com/bithavoc/winston-middleware.git"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "node_modules/.bin/mocha --reporter spec",
|
|
32
32
|
"test-travis": "node_modules/.bin/mocha --require blanket --reporter travis-cov",
|
|
33
|
-
"test-coverage": "node_modules/.bin/mocha --require blanket --reporter html-cov
|
|
33
|
+
"test-coverage": "node_modules/.bin/mocha --require blanket --reporter html-cov > coverage.html || true"
|
|
34
34
|
},
|
|
35
35
|
"config": {
|
|
36
36
|
"travis-cov": {
|
|
@@ -52,14 +52,15 @@
|
|
|
52
52
|
"winston": "~1.0.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"blanket": "
|
|
56
|
-
"mocha": "
|
|
57
|
-
"node-mocks-http": "
|
|
58
|
-
"
|
|
59
|
-
"
|
|
55
|
+
"blanket": "^1.2.2",
|
|
56
|
+
"mocha": "^2.4.5",
|
|
57
|
+
"node-mocks-http": "^1.5.1",
|
|
58
|
+
"promise": "^7.1.1",
|
|
59
|
+
"should": "^8.2.2",
|
|
60
|
+
"travis-cov": "^0.2.5"
|
|
60
61
|
},
|
|
61
62
|
"engines": {
|
|
62
|
-
"node": ">=0.
|
|
63
|
+
"node": ">=0.10.0"
|
|
63
64
|
},
|
|
64
65
|
"license": "MIT",
|
|
65
66
|
"contributors": [
|