Skip to content

Commit 05f7c33

Browse files
committed
Merge pull request #34 from AnyFetch/restify-logger
Use restify-logger
2 parents 4f45697 + d2bf6ff commit 05f7c33

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
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);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
],
1919
"dependencies": {
2020
"async": "^0.9.0",
21-
"morgan": "^1.3.2",
2221
"rarity": "^2.1.1",
2322
"restify": "^2.8.1",
23+
"restify-logger": "^1.0.0",
2424
"supertest": "^0.13.0"
2525
},
2626
"devDependencies": {

0 commit comments

Comments
 (0)