From 6508c702c1e63fa7c1192073edcf01bd9efb576b Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 10 Mar 2021 11:41:54 +0100 Subject: [PATCH 1/3] log url and options in connection attemp --- lib/model/dbConn.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/model/dbConn.js b/lib/model/dbConn.js index b833501..b4b56f1 100644 --- a/lib/model/dbConn.js +++ b/lib/model/dbConn.js @@ -76,10 +76,7 @@ function init(host, db, port, username, password, options, callback) { return previous; } - const hosts = host - .split(',') - .map(addPort) - .reduce(commaConcat, ''); + const hosts = host.split(',').map(addPort).reduce(commaConcat, ''); url = 'mongodb://' + credentials + hosts + '/' + db; @@ -105,46 +102,52 @@ function init(host, db, port, username, password, options, callback) { } function connectionAttempt(url, options, callback) { - logger.info(context, 'Attempting to connect to MongoDB instance. Attempt %d', retries); + logger.info( + context, + 'Attempting to connect to MongoDB instance with url %j and options %j. Attempt %d', + url, + options, + retries + ); // just to avoid warnings with recent mongoose versions options.useNewUrlParser = true; options.useUnifiedTopology = true; mongoose.set('useCreateIndex', true); /* eslint-disable-next-line no-unused-vars */ - const candidateDb = mongoose.createConnection(url, options, function(error, result) { + const candidateDb = mongoose.createConnection(url, options, function (error, result) { if (error) { logger.error(context, 'MONGODB-001: Error trying to connect to MongoDB: %s', error); lastError = error; } else { defaultDb = candidateDb; - defaultDb.on('error', function(error) { + defaultDb.on('error', function (error) { logger.error(context, 'Mongo Driver error: %j', error); }); /* eslint-disable-next-line no-unused-vars */ - defaultDb.on('connecting', function(error) { + defaultDb.on('connecting', function (error) { logger.debug(context, 'Mongo Driver connecting'); }); - defaultDb.on('connected', function() { + defaultDb.on('connected', function () { logger.debug(context, 'Mongo Driver connected'); }); - defaultDb.on('reconnected', function() { + defaultDb.on('reconnected', function () { logger.debug(context, 'Mongo Driver reconnected'); }); - defaultDb.on('disconnected', function() { + defaultDb.on('disconnected', function () { logger.debug(context, 'Mongo Driver disconnected'); }); - defaultDb.on('reconnectFailed', function() { + defaultDb.on('reconnectFailed', function () { logger.error(context, 'MONGODB-004: MongoDB connection was lost'); process.exit(1); }); - defaultDb.on('disconnecting', function() { + defaultDb.on('disconnecting', function () { logger.debug(context, 'Mongo Driver disconnecting'); }); - defaultDb.on('open', function() { + defaultDb.on('open', function () { logger.debug(context, 'Mongo Driver open'); }); - defaultDb.on('close', function() { + defaultDb.on('close', function () { logger.debug(context, 'Mongo Driver close'); }); } From 1bb225b784e926c0980984954db544e20f40f69a Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 10 Mar 2021 12:27:56 +0100 Subject: [PATCH 2/3] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index a999cc6..a39028c 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- Log db uri and options in mongo connection - Fix: log about getProtocol result - Fix: ensure protocol exists before remove it (#234) - Fix: print URI in logs about redirection error (#232) From 878144bdedc9466286bcf5b508af84d32fd062ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 10 Mar 2021 12:30:30 +0100 Subject: [PATCH 3/3] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index a39028c..2b60310 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,4 +1,4 @@ -- Log db uri and options in mongo connection +- Add: db uri and options in mongo connection log INFO trace - Fix: log about getProtocol result - Fix: ensure protocol exists before remove it (#234) - Fix: print URI in logs about redirection error (#232)