Skip to content

Commit a61b8cd

Browse files
committed
refactor(NODE-4685): hardcode component to env var mapping
1 parent 8ea8ce8 commit a61b8cd

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

test/tools/unified-spec-runner/entities.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,22 @@ export class UnifiedMongoClient extends MongoClient {
178178
serverDescriptionChangedEvent: 'serverDescriptionChanged'
179179
} as const;
180180

181+
static LOGGING_COMPONENT_TO_ENV_VAR_NAME = {
182+
command: 'MONGODB_LOG_COMMAND',
183+
serverSelection: 'MONGODB_LOG_SERVER_SELECTION',
184+
connection: 'MONGODB_LOG_CONNECTION',
185+
topology: 'MONGODB_LOG_TOPOLOGY'
186+
} as const;
187+
181188
constructor(uri: string, description: ClientEntity) {
182189
const logCollector = new UnifiedLogCollector();
183190
const componentSeverities = {
184191
MONGODB_LOG_ALL: 'off'
185192
};
186-
const camelToUpperSnake = (s: string) => {
187-
const output: string[] = [];
188-
for (const c of s) {
189-
if (/[A-Z]/.test(c)) {
190-
output.push('_');
191-
output.push(c);
192-
} else {
193-
output.push(c);
194-
}
195-
}
196-
return output.join('').toUpperCase();
197-
};
198193

199194
// NOTE: this is done to override the logger environment variables
200195
for (const key in description.observeLogMessages) {
201-
componentSeverities['MONGODB_LOG_' + camelToUpperSnake(key)] =
196+
componentSeverities[UnifiedMongoClient.LOGGING_COMPONENT_TO_ENV_VAR_NAME[key]] =
202197
description.observeLogMessages[key];
203198
}
204199

0 commit comments

Comments
 (0)