@@ -251,8 +251,11 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
251251 this [ kMetrics ] = new ConnectionPoolMetrics ( ) ;
252252 this [ kProcessingWaitQueue ] = false ;
253253
254+ this . mongoLogger = this [ kServer ] . topology . client . mongoLogger ;
255+ this . component = 'connection' ;
256+
254257 process . nextTick ( ( ) => {
255- this . emit ( ConnectionPool . CONNECTION_POOL_CREATED , new ConnectionPoolCreatedEvent ( this ) ) ;
258+ this . emitAndLog ( ConnectionPool . CONNECTION_POOL_CREATED , new ConnectionPoolCreatedEvent ( this ) ) ;
256259 } ) ;
257260 }
258261
@@ -337,7 +340,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
337340 return ;
338341 }
339342 this [ kPoolState ] = PoolState . ready ;
340- this . emit ( ConnectionPool . CONNECTION_POOL_READY , new ConnectionPoolReadyEvent ( this ) ) ;
343+ this . emitAndLog ( ConnectionPool . CONNECTION_POOL_READY , new ConnectionPoolReadyEvent ( this ) ) ;
341344 clearTimeout ( this [ kMinPoolSizeTimer ] ) ;
342345 this . ensureMinPoolSize ( ) ;
343346 }
@@ -348,7 +351,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
348351 * explicitly destroyed by the new owner.
349352 */
350353 checkOut ( callback : Callback < Connection > ) : void {
351- this . emit (
354+ this . emitAndLog (
352355 ConnectionPool . CONNECTION_CHECK_OUT_STARTED ,
353356 new ConnectionCheckOutStartedEvent ( this )
354357 ) ;
@@ -360,7 +363,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
360363 waitQueueMember [ kCancelled ] = true ;
361364 waitQueueMember . timer = undefined ;
362365
363- this . emit (
366+ this . emitAndLog (
364367 ConnectionPool . CONNECTION_CHECK_OUT_FAILED ,
365368 new ConnectionCheckOutFailedEvent ( this , 'timeout' )
366369 ) ;
@@ -398,7 +401,10 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
398401 }
399402
400403 this [ kCheckedOut ] . delete ( connection ) ;
401- this . emit ( ConnectionPool . CONNECTION_CHECKED_IN , new ConnectionCheckedInEvent ( this , connection ) ) ;
404+ this . emitAndLog (
405+ ConnectionPool . CONNECTION_CHECKED_IN ,
406+ new ConnectionCheckedInEvent ( this , connection )
407+ ) ;
402408
403409 if ( willDestroy ) {
404410 const reason = connection . closed ? 'error' : poolClosed ? 'poolClosed' : 'stale' ;
@@ -437,7 +443,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
437443 // Increment the generation for the service id.
438444 this . serviceGenerations . set ( sid , generation + 1 ) ;
439445 }
440- this . emit (
446+ this . emitAndLog (
441447 ConnectionPool . CONNECTION_POOL_CLEARED ,
442448 new ConnectionPoolClearedEvent ( this , { serviceId } )
443449 ) ;
@@ -452,9 +458,11 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
452458
453459 this . clearMinPoolSizeTimer ( ) ;
454460 if ( ! alreadyPaused ) {
455- this . emit (
461+ this . emitAndLog (
456462 ConnectionPool . CONNECTION_POOL_CLEARED ,
457- new ConnectionPoolClearedEvent ( this , { interruptInUseConnections } )
463+ new ConnectionPoolClearedEvent ( this , {
464+ interruptInUseConnections
465+ } )
458466 ) ;
459467 }
460468
@@ -509,15 +517,15 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
509517 eachAsync < Connection > (
510518 this [ kConnections ] . toArray ( ) ,
511519 ( conn , cb ) => {
512- this . emit (
520+ this . emitAndLog (
513521 ConnectionPool . CONNECTION_CLOSED ,
514522 new ConnectionClosedEvent ( this , conn , 'poolClosed' )
515523 ) ;
516524 conn . destroy ( { force : ! ! options . force } , cb ) ;
517525 } ,
518526 err => {
519527 this [ kConnections ] . clear ( ) ;
520- this . emit ( ConnectionPool . CONNECTION_POOL_CLOSED , new ConnectionPoolClosedEvent ( this ) ) ;
528+ this . emitAndLog ( ConnectionPool . CONNECTION_POOL_CLOSED , new ConnectionPoolClosedEvent ( this ) ) ;
521529 callback ( err ) ;
522530 }
523531 ) ;
@@ -645,7 +653,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
645653 connection : Connection ,
646654 reason : 'error' | 'idle' | 'stale' | 'poolClosed'
647655 ) {
648- this . emit (
656+ this . emitAndLog (
649657 ConnectionPool . CONNECTION_CLOSED ,
650658 new ConnectionClosedEvent ( this , connection , reason )
651659 ) ;
@@ -694,15 +702,15 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
694702
695703 this [ kPending ] ++ ;
696704 // This is our version of a "virtual" no-I/O connection as the spec requires
697- this . emit (
705+ this . emitAndLog (
698706 ConnectionPool . CONNECTION_CREATED ,
699707 new ConnectionCreatedEvent ( this , { id : connectOptions . id } )
700708 ) ;
701709
702710 connect ( connectOptions , ( err , connection ) => {
703711 if ( err || ! connection ) {
704712 this [ kPending ] -- ;
705- this . emit (
713+ this . emitAndLog (
706714 ConnectionPool . CONNECTION_CLOSED ,
707715 new ConnectionClosedEvent (
708716 this ,
@@ -750,7 +758,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
750758 }
751759
752760 connection . markAvailable ( ) ;
753- this . emit ( ConnectionPool . CONNECTION_READY , new ConnectionReadyEvent ( this , connection ) ) ;
761+ this . emitAndLog ( ConnectionPool . CONNECTION_READY , new ConnectionReadyEvent ( this , connection ) ) ;
754762
755763 this [ kPending ] -- ;
756764 callback ( undefined , connection ) ;
@@ -819,7 +827,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
819827 if ( this [ kPoolState ] !== PoolState . ready ) {
820828 const reason = this . closed ? 'poolClosed' : 'connectionError' ;
821829 const error = this . closed ? new PoolClosedError ( this ) : new PoolClearedError ( this ) ;
822- this . emit (
830+ this . emitAndLog (
823831 ConnectionPool . CONNECTION_CHECK_OUT_FAILED ,
824832 new ConnectionCheckOutFailedEvent ( this , reason , error )
825833 ) ;
@@ -842,7 +850,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
842850
843851 if ( ! this . destroyConnectionIfPerished ( connection ) ) {
844852 this [ kCheckedOut ] . add ( connection ) ;
845- this . emit (
853+ this . emitAndLog (
846854 ConnectionPool . CONNECTION_CHECKED_OUT ,
847855 new ConnectionCheckedOutEvent ( this , connection )
848856 ) ;
@@ -872,14 +880,14 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
872880 }
873881 } else {
874882 if ( err ) {
875- this . emit (
883+ this . emitAndLog (
876884 ConnectionPool . CONNECTION_CHECK_OUT_FAILED ,
877885 // TODO(NODE-5192): Remove this cast
878886 new ConnectionCheckOutFailedEvent ( this , 'connectionError' , err as MongoError )
879887 ) ;
880888 } else if ( connection ) {
881889 this [ kCheckedOut ] . add ( connection ) ;
882- this . emit (
890+ this . emitAndLog (
883891 ConnectionPool . CONNECTION_CHECKED_OUT ,
884892 new ConnectionCheckedOutEvent ( this , connection )
885893 ) ;
0 commit comments