From e44dae66714b5ddb21cf2af17e83681c3bb1249d Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Fri, 20 Oct 2017 15:36:12 +0000 Subject: Fix logging errors Change-Id: Ibb5182e7eff9a1c2d079da28a46d09cb2c700592 Issue-Id: DCAEGEN2-171 Signed-off-by: Jack Lucas --- lib/logging.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/logging.js') diff --git a/lib/logging.js b/lib/logging.js index 4d85898..a21f37e 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -140,7 +140,7 @@ const formatAuditRecord = function(req, status, extra) { rec[AUDIT_CATLOGLEVEL] = "INFO"; // The audit records are informational, regardless of the outcome of the operation rec[AUDIT_SRVIP] = req.socket.address().address; rec[AUDIT_ELAPSED] = end - req.startTime; - rec[AUDIT_SERVER] = req.hostname // From the Host header, again + rec[AUDIT_SERVER] = req.hostname; // From the Host header, again rec[AUDIT_CLIENTIP] = req.connection.remoteAddress; if (extra) { @@ -169,8 +169,9 @@ const formatMetricsRecord = function(req, opInfo, extra) { rec[METRICS_REQID] = req.dcaeReqId; rec[METRICS_SRVNAME] = req.hostname; // Use name from the host header rec[METRICS_SVCNAME] = req.method + ' ' + req.originalUrl; // Method and URL identify the operation being performed - rec[METRICS_CLIENTIP] = req.connection.remoteAddress; - rec[METRICS_SRVIP] = req.socket.address().address; + /* Defense: some clients will pass in a req that's incomplete */ + if (req.connection) {rec[METRICS_CLIENTIP] = req.connection.remoteAddress;} + if (req.socket) {rec[METRICS_SRVIP] = req.socket.address().address;} } else { /* No incoming request */ @@ -259,7 +260,7 @@ exports.getLogger = function() { debug: function(reqId, msg) { debugLogger.debug(formatDebugRecord(reqId, msg)); } - } + }; }; exports.setLevel = function(level) { -- cgit 1.2.3-korg