forked from uberproxy/uberproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogs.js
More file actions
57 lines (48 loc) · 1.29 KB
/
logs.js
File metadata and controls
57 lines (48 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var Winston = require('winston');
var container = new Winston.Container();
function delay(next) {
return function() {
var args = arguments;
setTimeout(function() {
next.apply(null, args);
}, 50);
};
}
function getLogger(type, label) {
container.add(type, {
console: {
handleExceptions: type == 'exception',
timestamp: true,
label: label + " - " + process.pid,
colorize: true
},
});
return container.get(type);
}
//getLogger("exception", "EXCEPTION").exitOnError = false;
var _response = getLogger("response", "RESPONSE");
var _request = getLogger('request', "REQUEST");
var response = delay(function(conn) {
_response.info("response", {
reqid: conn.reqid,
response_time: new Date - conn.started,
status: conn.statusCode,
worker: (conn.worker||{}).address,
});
});
var request = delay(function(conn) {
_request.info("request", {
reqid: conn.reqid,
date: conn.started,
method: conn.method,
hostname: conn.host,
path: conn.url,
ip: conn.ip,
});
});
function Logging(Proxy) {
Proxy.on('request', request);
Proxy.on('response', response);
}
exports.plugin = Logging;