@@ -126,10 +126,30 @@ export interface MongoLoggerEnvOptions {
126126 MONGODB_LOG_PATH ?: string ;
127127}
128128
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+
129145/** @internal */
130146export interface MongoLoggerMongoClientOptions {
131147 /** Destination for log messages */
132148 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 ;
133153}
134154
135155/** @internal */
@@ -148,7 +168,6 @@ export interface MongoLoggerOptions {
148168 /** Default severity level to be used if any of the above are unset */
149169 default : SeverityLevel ;
150170 } ;
151-
152171 /** Max length of embedded EJSON docs. Setting to 0 disables truncation. Defaults to 1000. */
153172 maxDocumentLength : number ;
154173 /** Destination for log messages. */
@@ -219,6 +238,18 @@ function resolveLogPath(
219238 return createStdioLogger ( process . stderr ) ;
220239}
221240
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+
222253/** @internal */
223254export interface Log extends Record < string , any > {
224255 t : Date ;
@@ -522,22 +553,45 @@ export class MongoLogger {
522553 ...clientOptions ,
523554 mongodbLogPath : resolveLogPath ( envOptions , clientOptions )
524555 } ;
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+ ) ;
527561
528562 return {
529563 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+ ) ,
537589 default : defaultSeverity
538590 } ,
539591 maxDocumentLength :
540- parseUnsignedInteger ( combinedOptions . MONGODB_LOG_MAX_DOCUMENT_LENGTH ) ?? 1000 ,
592+ combinedOptions . mongodbLogMaxDocumentLength ??
593+ parseUnsignedInteger ( combinedOptions . MONGODB_LOG_MAX_DOCUMENT_LENGTH ) ??
594+ 1000 ,
541595 logDestination : combinedOptions . mongodbLogPath
542596 } ;
543597 }
0 commit comments