Skip to content

Commit 79932db

Browse files
committed
refactor: integrate logger into CMAP connection pool
1 parent 5995d1d commit 79932db

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/cmap/connection_pool.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Denque = require('denque');
44
const EventEmitter = require('events').EventEmitter;
5+
const Logger = require('../core/connection/logger');
56
const makeCounter = require('../utils').makeCounter;
67
const MongoError = require('../core/error').MongoError;
78
const Connection = require('./connection').Connection;
@@ -25,6 +26,7 @@ const ConnectionCheckedOutEvent = events.ConnectionCheckedOutEvent;
2526
const ConnectionCheckedInEvent = events.ConnectionCheckedInEvent;
2627
const ConnectionPoolClearedEvent = events.ConnectionPoolClearedEvent;
2728

29+
const kLogger = Symbol('logger');
2830
const kConnections = Symbol('connections');
2931
const kPermits = Symbol('permits');
3032
const kMinPoolSizeTimer = Symbol('minPoolSizeTimer');
@@ -159,9 +161,12 @@ class ConnectionPool extends EventEmitter {
159161
});
160162

161163
if (options.minSize > options.maxSize) {
162-
throw new TypeError('Pool minimum size must not be greater than maxiumum pool size');
164+
throw new TypeError(
165+
'Connection pool minimum size must not be greater than maxiumum pool size'
166+
);
163167
}
164168

169+
this[kLogger] = Logger('ConnectionPool', options);
165170
this[kConnections] = new Denque();
166171
this[kPermits] = this.options.maxPoolSize;
167172
this[kMinPoolSizeTimer] = undefined;
@@ -354,11 +359,6 @@ class ConnectionPool extends EventEmitter {
354359
get address() {
355360
return `${this.options.host}:${this.options.port}`;
356361
}
357-
358-
// Private Helpers
359-
_propagateError() {
360-
return;
361-
}
362362
}
363363

364364
function ensureMinPoolSize(pool) {
@@ -395,9 +395,7 @@ function createConnection(pool, callback) {
395395
connect(connectOptions, pool[kCancellationToken], (err, connection) => {
396396
if (err) {
397397
pool[kPermits]++;
398-
399-
// NOTE: integrate logger here
400-
pool._propagateError(err);
398+
pool[kLogger].debug(`connection attempt failed with error [${JSON.stringify(err)}]`);
401399
if (typeof callback === 'function') {
402400
callback(err);
403401
}

0 commit comments

Comments
 (0)