Sending a log message with a non-object value for the req
property to the bunyan
CLI causes it to crash with an Object.keys called on non-object
message. This change fixes that.
This commit is contained in:
parent
7b08dd607d
commit
784eb0859f
1 changed files with 12 additions and 5 deletions
17
bin/bunyan
17
bin/bunyan
|
@ -754,14 +754,21 @@ function emitRecord(rec, line, opts, stylize) {
|
||||||
var req = rec.req;
|
var req = rec.req;
|
||||||
delete rec.req;
|
delete rec.req;
|
||||||
var headers = req.headers;
|
var headers = req.headers;
|
||||||
|
if (!headers) {
|
||||||
|
headers = '';
|
||||||
|
}
|
||||||
|
else if (typeof headers === 'string') {
|
||||||
|
headers = '\n' + headers;
|
||||||
|
}
|
||||||
|
else if (typeof headers === 'object') {
|
||||||
|
headers = '\n' + Object.keys(headers).map(function (h) {
|
||||||
|
return h + ': ' + headers[h];
|
||||||
|
}).join('\n');
|
||||||
|
}
|
||||||
var s = format('%s %s HTTP/%s%s', req.method,
|
var s = format('%s %s HTTP/%s%s', req.method,
|
||||||
req.url,
|
req.url,
|
||||||
req.httpVersion || '1.1',
|
req.httpVersion || '1.1',
|
||||||
(headers ?
|
headers
|
||||||
'\n' + Object.keys(headers).map(function (h) {
|
|
||||||
return h + ': ' + headers[h];
|
|
||||||
}).join('\n') :
|
|
||||||
'')
|
|
||||||
);
|
);
|
||||||
delete req.url;
|
delete req.url;
|
||||||
delete req.method;
|
delete req.method;
|
||||||
|
|
Loading…
Reference in a new issue