Skip to content

Commit d2bf6ff

Browse files
committed
Use restify-logger
1 parent d214c00 commit d2bf6ff

File tree

1 file changed

+7
-31
lines changed

1 file changed

+7
-31
lines changed

lib/middlewares/logger.js

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
11
'use strict';
22

3-
var logger = require('morgan');
4-
5-
var customLogger = function(tokens, req, res) {
6-
// Don't log on test
7-
if(process.env.NODE_ENV === "test") {
8-
return;
9-
}
10-
11-
// Don't log OPTIONS call, CORS.
12-
if(req.method === "OPTIONS") {
13-
return;
14-
}
15-
16-
var status = res.statusCode;
17-
var color = 32;
18-
var error = "";
19-
if(status >= 500) {
20-
color = 31;
21-
error = res._body;
22-
}
23-
else if(status >= 400){
24-
color = 33;
25-
error = res._body;
26-
}
27-
else if(status >= 300) {
28-
color = 36;
29-
}
30-
31-
return '\x1b[90m' + req.method + ' ' + req.url + ' ' + '\x1b[' + color + 'm' + res.statusCode + ' \x1b[90m' + (new Date() - req._startTime) + 'ms' + '\x1b[0m' + ' ' + error;
3+
var logger = require('restify-logger');
324

5+
var filter = function filter(req, res) {
6+
return process.env.NODE_ENV !== "test" && req.method !== "OPTIONS";
337
};
348

9+
var display = function display(req, res) {
10+
return (req.token && req.token.accountName) ? req.token.accountName : '???';
11+
};
3512

36-
module.exports = logger(customLogger);
37-
module.exports.customLogger = customLogger;
13+
module.exports = logger(filter, display);

0 commit comments

Comments
 (0)