diff --git a/lib/appenders/gelf.js b/lib/appenders/gelf.js index 1ae09e6..d62a704 100644 --- a/lib/appenders/gelf.js +++ b/lib/appenders/gelf.js @@ -114,11 +114,11 @@ function gelfAppender(layout, host, port, hostname, facility) { } function sendPacket(packet) { - try { - client.send(packet, 0, packet.length, port, host); - } catch (e) { - // do nothing - } + client.send(packet, 0, packet.length, port, host, err => { + if (err) { + console.error(err); + } + }); } return loggingEvent => { diff --git a/lib/connect-logger.js b/lib/connect-logger.js index 0654ed2..abeba12 100755 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -135,7 +135,7 @@ function assembleTokens(req, res, customTokens) { }; const defaultTokens = []; - defaultTokens.push({ token: ':url', replacement: req.originalUrl }); + defaultTokens.push({ token: ':url', replacement: getUrl(req) }); defaultTokens.push({ token: ':protocol', replacement: req.protocol }); defaultTokens.push({ token: ':hostname', replacement: req.hostname }); defaultTokens.push({ token: ':method', replacement: req.method }); @@ -186,6 +186,20 @@ function assembleTokens(req, res, customTokens) { return arrayUniqueTokens(customTokens.concat(defaultTokens)); } +/** + * Return request url path, + * adding this function prevents the Cyclomatic Complexity, + * for the assemble_tokens function at low, to pass the tests. + * + * @param {IncomingMessage} req + * @return {String} + * @api private + */ + +function getUrl(req) { + return req.originalUrl || req.url; +} + /** * Return formatted log line. * diff --git a/package.json b/package.json index 2f2a58f..ccb5cb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "log4js", - "version": "0.6.37", + "version": "0.6.38", "description": "Port of Log4js to work with node.", "keywords": [ "logging",