@@ -126,10 +126,30 @@ export interface MongoLoggerEnvOptions {
126
126
MONGODB_LOG_PATH ?: string ;
127
127
}
128
128
129
+ /** @internal */
130
+ export interface LogComponentSeveritiesClientOptions {
131
+ /** Optional severity level for command component */
132
+ command ?: SeverityLevel ;
133
+ /** Optional severity level for topology component */
134
+ topology ?: SeverityLevel ;
135
+ /** Optionsl severity level for server selection component */
136
+ serverSelection ?: SeverityLevel ;
137
+ /** Optional severity level for connection component */
138
+ connection ?: SeverityLevel ;
139
+ /** Optional severity level for client component */
140
+ client ?: SeverityLevel ;
141
+ /** Optional default severity level to be used if any of the above are unset */
142
+ default ?: SeverityLevel ;
143
+ }
144
+
129
145
/** @internal */
130
146
export interface MongoLoggerMongoClientOptions {
131
147
/** Destination for log messages */
132
148
mongodbLogPath ?: 'stdout' | 'stderr' | MongoDBLogWritable ;
149
+ /** Severity levels for logger components */
150
+ mongodbLogComponentSeverities ?: LogComponentSeveritiesClientOptions ;
151
+ /** Max length of embedded EJSON docs. Setting to 0 disables truncation. Defaults to 1000. */
152
+ mongodbLogMaxDocumentLength ?: number ;
133
153
}
134
154
135
155
/** @internal */
@@ -148,7 +168,6 @@ export interface MongoLoggerOptions {
148
168
/** Default severity level to be used if any of the above are unset */
149
169
default : SeverityLevel ;
150
170
} ;
151
-
152
171
/** Max length of embedded EJSON docs. Setting to 0 disables truncation. Defaults to 1000. */
153
172
maxDocumentLength : number ;
154
173
/** Destination for log messages. */
@@ -219,6 +238,18 @@ function resolveLogPath(
219
238
return createStdioLogger ( process . stderr ) ;
220
239
}
221
240
241
+ function resolveSeverityConfiguration (
242
+ clientOption : string | undefined ,
243
+ environmentOption : string | undefined ,
244
+ defaultSeverity : SeverityLevel
245
+ ) : SeverityLevel {
246
+ return (
247
+ parseSeverityFromString ( clientOption ) ??
248
+ parseSeverityFromString ( environmentOption ) ??
249
+ defaultSeverity
250
+ ) ;
251
+ }
252
+
222
253
/** @internal */
223
254
export interface Log extends Record < string , any > {
224
255
t : Date ;
@@ -522,22 +553,45 @@ export class MongoLogger {
522
553
...clientOptions ,
523
554
mongodbLogPath : resolveLogPath ( envOptions , clientOptions )
524
555
} ;
525
- const defaultSeverity =
526
- parseSeverityFromString ( combinedOptions . MONGODB_LOG_ALL ) ?? SeverityLevel . OFF ;
556
+ const defaultSeverity = resolveSeverityConfiguration (
557
+ combinedOptions . mongodbLogComponentSeverities ?. default ,
558
+ combinedOptions . MONGODB_LOG_ALL ,
559
+ SeverityLevel . OFF
560
+ ) ;
527
561
528
562
return {
529
563
componentSeverities : {
530
- command : parseSeverityFromString ( combinedOptions . MONGODB_LOG_COMMAND ) ?? defaultSeverity ,
531
- topology : parseSeverityFromString ( combinedOptions . MONGODB_LOG_TOPOLOGY ) ?? defaultSeverity ,
532
- serverSelection :
533
- parseSeverityFromString ( combinedOptions . MONGODB_LOG_SERVER_SELECTION ) ?? defaultSeverity ,
534
- connection :
535
- parseSeverityFromString ( combinedOptions . MONGODB_LOG_CONNECTION ) ?? defaultSeverity ,
536
- client : parseSeverityFromString ( combinedOptions . MONGODB_LOG_CLIENT ) ?? defaultSeverity ,
564
+ command : resolveSeverityConfiguration (
565
+ combinedOptions . mongodbLogComponentSeverities ?. command ,
566
+ combinedOptions . MONGODB_LOG_COMMAND ,
567
+ defaultSeverity
568
+ ) ,
569
+ topology : resolveSeverityConfiguration (
570
+ combinedOptions . mongodbLogComponentSeverities ?. topology ,
571
+ combinedOptions . MONGODB_LOG_TOPOLOGY ,
572
+ defaultSeverity
573
+ ) ,
574
+ serverSelection : resolveSeverityConfiguration (
575
+ combinedOptions . mongodbLogComponentSeverities ?. serverSelection ,
576
+ combinedOptions . MONGODB_LOG_SERVER_SELECTION ,
577
+ defaultSeverity
578
+ ) ,
579
+ connection : resolveSeverityConfiguration (
580
+ combinedOptions . mongodbLogComponentSeverities ?. connection ,
581
+ combinedOptions . MONGODB_LOG_CONNECTION ,
582
+ defaultSeverity
583
+ ) ,
584
+ client : resolveSeverityConfiguration (
585
+ combinedOptions . mongodbLogComponentSeverities ?. client ,
586
+ combinedOptions . MONGODB_LOG_CLIENT ,
587
+ defaultSeverity
588
+ ) ,
537
589
default : defaultSeverity
538
590
} ,
539
591
maxDocumentLength :
540
- parseUnsignedInteger ( combinedOptions . MONGODB_LOG_MAX_DOCUMENT_LENGTH ) ?? 1000 ,
592
+ combinedOptions . mongodbLogMaxDocumentLength ??
593
+ parseUnsignedInteger ( combinedOptions . MONGODB_LOG_MAX_DOCUMENT_LENGTH ) ??
594
+ 1000 ,
541
595
logDestination : combinedOptions . mongodbLogPath
542
596
} ;
543
597
}
0 commit comments