@@ -275,6 +275,16 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
275
275
) ;
276
276
}
277
277
278
+ private get shouldEmitAndLogCommand ( ) : boolean {
279
+ return (
280
+ ( this . monitorCommands ||
281
+ ( this . established &&
282
+ ! this . authContext ?. reauthenticating &&
283
+ this . mongoLogger ?. willLog ( SeverityLevel . DEBUG , MongoLoggableComponent . COMMAND ) ) ) ??
284
+ false
285
+ ) ;
286
+ }
287
+
278
288
public markAvailable ( ) : void {
279
289
this . lastUseTime = now ( ) ;
280
290
}
@@ -458,11 +468,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
458
468
const message = this . prepareCommand ( ns . db , command , options ) ;
459
469
460
470
let started = 0 ;
461
- if (
462
- this . monitorCommands ||
463
- ( this . established &&
464
- this . mongoLogger ?. willLog ( SeverityLevel . DEBUG , MongoLoggableComponent . COMMAND ) )
465
- ) {
471
+ if ( this . shouldEmitAndLogCommand ) {
466
472
started = now ( ) ;
467
473
this . emitAndLogCommand (
468
474
this . monitorCommands ,
@@ -488,11 +494,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
488
494
throw new MongoServerError ( document ) ;
489
495
}
490
496
491
- if (
492
- this . monitorCommands ||
493
- ( this . established &&
494
- this . mongoLogger ?. willLog ( SeverityLevel . DEBUG , MongoLoggableComponent . COMMAND ) )
495
- ) {
497
+ if ( this . shouldEmitAndLogCommand ) {
496
498
this . emitAndLogCommand (
497
499
this . monitorCommands ,
498
500
Connection . COMMAND_SUCCEEDED ,
@@ -512,11 +514,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
512
514
this . controller . signal . throwIfAborted ( ) ;
513
515
}
514
516
} catch ( error ) {
515
- if (
516
- this . monitorCommands ||
517
- ( this . established &&
518
- this . mongoLogger ?. willLog ( SeverityLevel . DEBUG , MongoLoggableComponent . COMMAND ) )
519
- ) {
517
+ if ( this . shouldEmitAndLogCommand ) {
520
518
if ( error . name === 'MongoWriteConcernError' ) {
521
519
this . emitAndLogCommand (
522
520
this . monitorCommands ,
0 commit comments