@@ -30,7 +30,6 @@ import {
3030 MongoClient ,
3131 type MongoClientOptions ,
3232 type MongoCredentials ,
33- type MongoDBLogWritable ,
3433 ReadConcern ,
3534 ReadPreference ,
3635 SENSITIVE_COMMANDS ,
@@ -128,6 +127,7 @@ export class UnifiedMongoClient extends MongoClient {
128127 cmapEvents : CmapEvent [ ] = [ ] ;
129128 sdamEvents : SdamEvent [ ] = [ ] ;
130129 failPoints : Document [ ] = [ ] ;
130+ logCollector ?: { buffer : LogMessage [ ] ; write : ( log : Log ) => void } ;
131131
132132 ignoredEvents : string [ ] ;
133133 observeSensitiveCommands : boolean ;
@@ -215,9 +215,11 @@ export class UnifiedMongoClient extends MongoClient {
215215 mongodbLogMaxDocumentLength : 1250
216216 } ;
217217
218+ let logCollector : { buffer : LogMessage [ ] ; write : ( log : Log ) => void } | undefined ;
219+
218220 if ( description . observeLogMessages != null ) {
219221 options . mongodbLogComponentSeverities = description . observeLogMessages ;
220- options . mongodbLogPath = {
222+ logCollector = {
221223 buffer : [ ] ,
222224 write ( log : Log ) : void {
223225 const transformedLog = {
@@ -228,13 +230,14 @@ export class UnifiedMongoClient extends MongoClient {
228230
229231 this . buffer . push ( transformedLog ) ;
230232 }
231- } as MongoDBLogWritable ;
233+ } ;
234+ options . mongodbLogPath = logCollector ;
232235 } else if ( config . loggingEnabled ) {
233236 config . setupLogging ?.( options , description . id ) ;
234237 }
235238
236239 super ( uri , options ) ;
237-
240+ this . logCollector = logCollector ;
238241 this . observedEventEmitter . on ( 'error' , ( ) => null ) ;
239242 this . observeSensitiveCommands = description . observeSensitiveCommands ?? false ;
240243
@@ -348,7 +351,7 @@ export class UnifiedMongoClient extends MongoClient {
348351 }
349352
350353 get collectedLogs ( ) : LogMessage [ ] {
351- return ( this . options . mongodbLogPath as unknown as { buffer : any [ ] } ) ?. buffer ?? [ ] ;
354+ return this . logCollector ?. buffer ?? [ ] ;
352355 }
353356}
354357
0 commit comments