forked from admazely/bunyan-serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserializers.js
50 lines (43 loc) · 1.06 KB
/
serializers.js
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
function isObject(x) {
return typeof(x) === 'object' && x !== null;
}
exports.res = function res(res) {
return {
toJSON: function() {
if (!isObject(res)) return res;
return {
statusCode: res.statusCode,
header: res._header
}
}
}
}
exports.req = function req(req) {
return {
toJSON: function() {
if (!isObject(req)) return req;
var connection = req.connection || {};
return {
method: req.method,
url: req.url,
headers: req.headers,
remoteAddress: connection.remoteAddress,
remotePort: connection.remotePort
};
}
}
}
exports.err = function err(err) {
if (!isObject(err)) return err;
var obj = {
message: err.message,
name: err.name,
stack: err.stack
};
Object.keys(err).forEach(function (k) {
if (err[k] !== undefined) {
obj[k] = err[k];
}
});
return obj;
};