@@ -30,7 +30,6 @@ import {
30
30
MongoClient ,
31
31
type MongoClientOptions ,
32
32
type MongoCredentials ,
33
- type MongoDBLogWritable ,
34
33
ReadConcern ,
35
34
ReadPreference ,
36
35
SENSITIVE_COMMANDS ,
@@ -128,6 +127,7 @@ export class UnifiedMongoClient extends MongoClient {
128
127
cmapEvents : CmapEvent [ ] = [ ] ;
129
128
sdamEvents : SdamEvent [ ] = [ ] ;
130
129
failPoints : Document [ ] = [ ] ;
130
+ logCollector ?: { buffer : LogMessage [ ] ; write : ( log : Log ) => void } ;
131
131
132
132
ignoredEvents : string [ ] ;
133
133
observeSensitiveCommands : boolean ;
@@ -215,9 +215,11 @@ export class UnifiedMongoClient extends MongoClient {
215
215
mongodbLogMaxDocumentLength : 1250
216
216
} ;
217
217
218
+ let logCollector : { buffer : LogMessage [ ] ; write : ( log : Log ) => void } | undefined ;
219
+
218
220
if ( description . observeLogMessages != null ) {
219
221
options . mongodbLogComponentSeverities = description . observeLogMessages ;
220
- options . mongodbLogPath = {
222
+ logCollector = {
221
223
buffer : [ ] ,
222
224
write ( log : Log ) : void {
223
225
const transformedLog = {
@@ -228,13 +230,14 @@ export class UnifiedMongoClient extends MongoClient {
228
230
229
231
this . buffer . push ( transformedLog ) ;
230
232
}
231
- } as MongoDBLogWritable ;
233
+ } ;
234
+ options . mongodbLogPath = logCollector ;
232
235
} else if ( config . loggingEnabled ) {
233
236
config . setupLogging ?.( options , description . id ) ;
234
237
}
235
238
236
239
super ( uri , options ) ;
237
-
240
+ this . logCollector = logCollector ;
238
241
this . observedEventEmitter . on ( 'error' , ( ) => null ) ;
239
242
this . observeSensitiveCommands = description . observeSensitiveCommands ?? false ;
240
243
@@ -348,7 +351,7 @@ export class UnifiedMongoClient extends MongoClient {
348
351
}
349
352
350
353
get collectedLogs ( ) : LogMessage [ ] {
351
- return ( this . options . mongodbLogPath as unknown as { buffer : any [ ] } ) ?. buffer ?? [ ] ;
354
+ return this . logCollector ?. buffer ?? [ ] ;
352
355
}
353
356
}
354
357
0 commit comments