winston-middleware 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/index.js +11 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -120,6 +120,12 @@ function errorLogger(options) {
120
120
 
121
121
  options.requestFilter = options.requestFilter || defaultRequestFilter;
122
122
  options.winstonInstance = options.winstonInstance || (new winston.Logger ({ transports: options.transports }));
123
+ options.msg = options.msg || 'middlewareError';
124
+
125
+ // Using mustache style templating
126
+ var template = _.template(options.msg, null, {
127
+ interpolate: /\{\{(.+?)\}\}/g
128
+ });
123
129
 
124
130
  return function (err, req, res, next) {
125
131
 
@@ -128,7 +134,7 @@ function errorLogger(options) {
128
134
  exceptionMeta.req = filterObject(req, requestWhitelist, options.requestFilter);
129
135
 
130
136
  // This is fire and forget, we don't want logging to hold up the request so don't wait for the callback
131
- options.winstonInstance.log('error', 'middlewareError', exceptionMeta);
137
+ options.winstonInstance.log('error', template({err: err, req: req, res: res}), exceptionMeta);
132
138
 
133
139
  next(err);
134
140
  };
@@ -211,8 +217,7 @@ function logger(options) {
211
217
  requestWhitelist = requestWhitelist.concat(req._routeWhitelists.req || []);
212
218
  responseWhitelist = responseWhitelist.concat(req._routeWhitelists.res || []);
213
219
 
214
- meta.req = filterObject(req, requestWhitelist, options.requestFilter);
215
- meta.res = filterObject(res, responseWhitelist, options.responseFilter);
220
+ meta.res = res;
216
221
 
217
222
  if (_.contains(responseWhitelist, 'body')) {
218
223
  if (chunk) {
@@ -223,6 +228,9 @@ function logger(options) {
223
228
  }
224
229
  }
225
230
 
231
+ meta.req = filterObject(req, requestWhitelist, options.requestFilter);
232
+ meta.res = filterObject(res, responseWhitelist, options.responseFilter);
233
+
226
234
  bodyWhitelist = req._routeWhitelists.body || [];
227
235
  blacklist = _.union(bodyBlacklist, (req._routeBlacklists.body || []));
228
236
 
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "middleware",
18
18
  "colors"
19
19
  ],
20
- "version": "1.0.0",
20
+ "version": "1.1.0",
21
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "https://github.com/bithavoc/winston-middleware.git"