winston-middleware 0.3.1 → 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 (3) hide show
  1. package/Readme.md +6 -0
  2. package/index.js +11 -3
  3. package/package.json +2 -2
package/Readme.md CHANGED
@@ -5,8 +5,14 @@
5
5
 
6
6
  ## Installation
7
7
 
8
+ Newcomers should start with the latest branch which makes use of winston 1.x.x:
9
+
8
10
  npm install winston-middleware
9
11
 
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
+
14
+ npm install winston-middleware@0.3.x --save
15
+
10
16
  ## Usage
11
17
 
12
18
  winston-middleware provides middlewares for request and error logging of your express.js application. It uses 'whitelists' to select properties from the request and (new in 0.2.x) response objects.
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": "0.3.1",
20
+ "version": "1.1.0",
21
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "https://github.com/bithavoc/winston-middleware.git"
@@ -49,7 +49,7 @@
49
49
  "dependencies": {
50
50
  "chalk": "~0.4.0",
51
51
  "underscore": "~1.5.2",
52
- "winston": "~0.9.0"
52
+ "winston": "~1.0.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "blanket": "~1.1.6",