diff --git a/.evergreen/config.yml b/.evergreen/config.yml index fa117c60268..09f3706c317 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -3517,7 +3517,7 @@ tasks: - {key: VERSION, value: v6.0-perf} - {key: TOPOLOGY, value: server} - {key: AUTH, value: noauth} - - {key: MONGODB_CLIENT_OPTIONS, value: '{"__enableMongoLogger":true,"__internalLoggerConfig":{"MONGODB_LOG_ALL":"trace","MONGODB_LOG_PATH":"stderr"}}'} + - {key: MONGODB_CLIENT_OPTIONS, value: '{"mongodbLogPath":"stderr","mongodbLogComponentSeverities":{"default":"trace"}}'} - func: install dependencies - func: bootstrap mongo-orchestration - func: run spec driver benchmarks diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 516e84644a0..450f3513ff8 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -564,7 +564,7 @@ SINGLETON_TASKS.push( updateExpansions({ VERSION: 'latest', TOPOLOGY: 'replica_set', - NODE_LTS_VERSION: LATEST_LTS + NODE_LTS_VERSION: LATEST_LTS }), { func: 'install dependencies' }, { func: 'bootstrap mongo-orchestration' }, @@ -750,11 +750,8 @@ function addPerformanceTasks() { monitorCommands: true }), makePerfTask('run-spec-benchmark-tests-node-server-logging', { - __enableMongoLogger: true, - __internalLoggerConfig: { - MONGODB_LOG_ALL: 'trace', - MONGODB_LOG_PATH: 'stderr' - } + mongodbLogPath: 'stderr', + mongodbLogComponentSeverities: { default: 'trace' } }) ]; diff --git a/.evergreen/run-benchmarks.sh b/.evergreen/run-benchmarks.sh index 74c56c5f3b1..c81d6924716 100644 --- a/.evergreen/run-benchmarks.sh +++ b/.evergreen/run-benchmarks.sh @@ -12,8 +12,8 @@ export MONGODB_CLIENT_OPTIONS=$MONGODB_CLIENT_OPTIONS npm run build:ts -# If MONGODB_CLIENT_OPTIONS contains __enableMongoLogger redirect stderr to a file -if [[ $MONGODB_CLIENT_OPTIONS == *"__enableMongoLogger"* ]]; then +# If MONGODB_CLIENT_OPTIONS contains mongodbLogComponentSeverities redirect stderr to a file +if [[ $MONGODB_CLIENT_OPTIONS == *"mongodbLogComponentSeverities"* ]]; then npm run check:bench 2> bench.log else npm run check:bench diff --git a/src/connection_string.ts b/src/connection_string.ts index 322d5ca51d2..f1b23e5ac71 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -22,13 +22,7 @@ import { type ServerApi, ServerApiVersion } from './mongo_client'; -import { - MongoLoggableComponent, - MongoLogger, - type MongoLoggerEnvOptions, - type MongoLoggerMongoClientOptions, - SeverityLevel -} from './mongo_logger'; +import { MongoLoggableComponent, MongoLogger, SeverityLevel } from './mongo_logger'; import { ReadConcern, type ReadConcernLevel } from './read_concern'; import { ReadPreference, type ReadPreferenceMode } from './read_preference'; import { ServerMonitoringMode } from './sdam/monitor'; @@ -528,12 +522,8 @@ export function parseOptions( ); } - mongoOptions.__enableMongoLogger = mongoOptions.__enableMongoLogger ?? false; - - let loggerEnvOptions: MongoLoggerEnvOptions = {}; - let loggerClientOptions: MongoLoggerMongoClientOptions = {}; - if (mongoOptions.__enableMongoLogger) { - loggerEnvOptions = { + mongoOptions.mongoLoggerOptions = MongoLogger.resolveOptions( + { MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND, MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY, MONGODB_LOG_SERVER_SELECTION: process.env.MONGODB_LOG_SERVER_SELECTION, @@ -541,18 +531,13 @@ export function parseOptions( MONGODB_LOG_CLIENT: process.env.MONGODB_LOG_CLIENT, MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL, MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH, - MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH, - ...mongoOptions.__internalLoggerConfig - }; - loggerClientOptions = { + MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH + }, + { mongodbLogPath: mongoOptions.mongodbLogPath, mongodbLogComponentSeverities: mongoOptions.mongodbLogComponentSeverities, mongodbLogMaxDocumentLength: mongoOptions.mongodbLogMaxDocumentLength - }; - } - mongoOptions.mongoLoggerOptions = MongoLogger.resolveOptions( - loggerEnvOptions, - loggerClientOptions + } ); mongoOptions.metadata = makeClientMetadata(mongoOptions); @@ -1232,52 +1217,6 @@ export const OPTIONS = { default: 0, type: 'int' }, - // Custom types for modifying core behavior - connectionType: { type: 'any' }, - srvPoller: { type: 'any' }, - // Accepted Node.js Options - allowPartialTrustChain: { type: 'any' }, - minDHSize: { type: 'any' }, - pskCallback: { type: 'any' }, - secureContext: { type: 'any' }, - enableTrace: { type: 'any' }, - requestCert: { type: 'any' }, - rejectUnauthorized: { type: 'any' }, - checkServerIdentity: { type: 'any' }, - ALPNProtocols: { type: 'any' }, - SNICallback: { type: 'any' }, - session: { type: 'any' }, - requestOCSP: { type: 'any' }, - localAddress: { type: 'any' }, - localPort: { type: 'any' }, - hints: { type: 'any' }, - lookup: { type: 'any' }, - ca: { type: 'any' }, - cert: { type: 'any' }, - ciphers: { type: 'any' }, - crl: { type: 'any' }, - ecdhCurve: { type: 'any' }, - key: { type: 'any' }, - passphrase: { type: 'any' }, - pfx: { type: 'any' }, - secureProtocol: { type: 'any' }, - index: { type: 'any' }, - // Legacy options from v3 era - useNewUrlParser: { - type: 'boolean', - deprecated: - 'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' - } as OptionDescriptor, - useUnifiedTopology: { - type: 'boolean', - deprecated: - 'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' - } as OptionDescriptor, - // MongoLogger - /** - * @internal - * TODO: NODE-5671 - remove internal flag - */ mongodbLogPath: { transform({ values: [value] }) { if ( @@ -1296,10 +1235,6 @@ export const OPTIONS = { return value; } }, - /** - * @internal - * TODO: NODE-5671 - remove internal flag - */ mongodbLogComponentSeverities: { transform({ values: [value] }) { if (typeof value !== 'object' || !value) { @@ -1325,14 +1260,49 @@ export const OPTIONS = { return value; } }, - /** - * @internal - * TODO: NODE-5671 - remove internal flag - */ mongodbLogMaxDocumentLength: { type: 'uint' }, - __enableMongoLogger: { type: 'boolean' }, - __skipPingOnConnect: { type: 'boolean' }, - __internalLoggerConfig: { type: 'record' } + // Custom types for modifying core behavior + connectionType: { type: 'any' }, + srvPoller: { type: 'any' }, + // Accepted Node.js Options + allowPartialTrustChain: { type: 'any' }, + minDHSize: { type: 'any' }, + pskCallback: { type: 'any' }, + secureContext: { type: 'any' }, + enableTrace: { type: 'any' }, + requestCert: { type: 'any' }, + rejectUnauthorized: { type: 'any' }, + checkServerIdentity: { type: 'any' }, + ALPNProtocols: { type: 'any' }, + SNICallback: { type: 'any' }, + session: { type: 'any' }, + requestOCSP: { type: 'any' }, + localAddress: { type: 'any' }, + localPort: { type: 'any' }, + hints: { type: 'any' }, + lookup: { type: 'any' }, + ca: { type: 'any' }, + cert: { type: 'any' }, + ciphers: { type: 'any' }, + crl: { type: 'any' }, + ecdhCurve: { type: 'any' }, + key: { type: 'any' }, + passphrase: { type: 'any' }, + pfx: { type: 'any' }, + secureProtocol: { type: 'any' }, + index: { type: 'any' }, + // Legacy options from v3 era + useNewUrlParser: { + type: 'boolean', + deprecated: + 'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' + } as OptionDescriptor, + useUnifiedTopology: { + type: 'boolean', + deprecated: + 'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' + } as OptionDescriptor, + __skipPingOnConnect: { type: 'boolean' } } as Record; export const DEFAULT_OPTIONS = new CaseInsensitiveMap( diff --git a/src/index.ts b/src/index.ts index a80cf54b891..dfc8ac4b8e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -120,6 +120,7 @@ export { CURSOR_FLAGS, CursorTimeoutMode } from './cursor/abstract_cursor'; export { MongoErrorLabel } from './error'; export { ExplainVerbosity } from './explain'; export { ServerApiVersion } from './mongo_client'; +export { MongoLoggableComponent, SeverityLevel } from './mongo_logger'; export { ReturnDocument } from './operations/find_and_modify'; export { ProfilingLevel } from './operations/set_profiling_level'; export { ReadConcernLevel } from './read_concern'; @@ -422,12 +423,10 @@ export type { LoggableServerHeartbeatStartedEvent, LoggableServerHeartbeatSucceededEvent, MongoDBLogWritable, - MongoLoggableComponent, MongoLogger, MongoLoggerEnvOptions, MongoLoggerMongoClientOptions, - MongoLoggerOptions, - SeverityLevel + MongoLoggerOptions } from './mongo_logger'; export type { Abortable, diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 579b98dea9b..82c955ccd31 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -27,7 +27,6 @@ import { type LogComponentSeveritiesClientOptions, type MongoDBLogWritable, MongoLogger, - type MongoLoggerEnvOptions, type MongoLoggerOptions, SeverityLevel } from './mongo_logger'; @@ -279,33 +278,29 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC proxyPassword?: string; /** Instructs the driver monitors to use a specific monitoring mode */ serverMonitoringMode?: ServerMonitoringMode; - - /** @internal */ - srvPoller?: SrvPoller; - /** @internal */ - connectionType?: typeof Connection; /** - * @internal - * TODO: NODE-5671 - remove internal flag + * @public + * Specifies the destination of the driver's logging. The default is stderr. */ mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable; /** - * @internal - * TODO: NODE-5671 - remove internal flag + * @public + * Enable logging level per component or use `default` to control any unset components. */ mongodbLogComponentSeverities?: LogComponentSeveritiesClientOptions; /** - * @internal - * TODO: NODE-5671 - remove internal flag + * @public + * All BSON documents are stringified to EJSON. This controls the maximum length of those strings. + * It is defaulted to 1000. */ mongodbLogMaxDocumentLength?: number; /** @internal */ - __skipPingOnConnect?: boolean; + srvPoller?: SrvPoller; /** @internal */ - __internalLoggerConfig?: MongoLoggerEnvOptions; + connectionType?: typeof Connection; /** @internal */ - __enableMongoLogger?: boolean; + __skipPingOnConnect?: boolean; } /** @public */ @@ -1062,8 +1057,4 @@ export interface MongoOptions timeoutMS?: number; /** @internal */ __skipPingOnConnect?: boolean; - /** @internal */ - __internalLoggerConfig?: Document; - /** @internal */ - __enableMongoLogger?: boolean; } diff --git a/src/mongo_logger.ts b/src/mongo_logger.ts index c6e581c59e8..90cfac37153 100644 --- a/src/mongo_logger.ts +++ b/src/mongo_logger.ts @@ -77,7 +77,11 @@ import type { } from './sdam/server_selection_events'; import { HostAddress, isPromiseLike, parseUnsignedInteger } from './utils'; -/** @internal */ +/** + * @public + * Severity levels align with unix syslog. + * Most typical driver functions will log to debug. + */ export const SeverityLevel = Object.freeze({ EMERGENCY: 'emergency', ALERT: 'alert', @@ -93,7 +97,7 @@ export const SeverityLevel = Object.freeze({ /** @internal */ export const DEFAULT_MAX_DOCUMENT_LENGTH = 1000; -/** @internal */ +/** @public */ export type SeverityLevel = (typeof SeverityLevel)[keyof typeof SeverityLevel]; /** @internal */ @@ -131,7 +135,7 @@ export const SEVERITY_LEVEL_MAP = new SeverityLevelMap([ [SeverityLevel.TRACE, 8] ]); -/** @internal */ +/** @public */ export const MongoLoggableComponent = Object.freeze({ COMMAND: 'command', TOPOLOGY: 'topology', @@ -140,7 +144,7 @@ export const MongoLoggableComponent = Object.freeze({ CLIENT: 'client' } as const); -/** @internal */ +/** @public */ export type MongoLoggableComponent = (typeof MongoLoggableComponent)[keyof typeof MongoLoggableComponent]; @@ -164,13 +168,13 @@ export interface MongoLoggerEnvOptions { MONGODB_LOG_PATH?: string; } -/** @internal */ +/** @public */ export interface LogComponentSeveritiesClientOptions { /** Optional severity level for command component */ command?: SeverityLevel; /** Optional severity level for topology component */ topology?: SeverityLevel; - /** Optionsl severity level for server selection component */ + /** Optional severity level for server selection component */ serverSelection?: SeverityLevel; /** Optional severity level for connection component */ connection?: SeverityLevel; @@ -292,7 +296,7 @@ function resolveSeverityConfiguration( ); } -/** @internal */ +/** @public */ export interface Log extends Record { t: Date; c: MongoLoggableComponent; @@ -301,10 +305,27 @@ export interface Log extends Record { } /** - * @internal - * TODO: NODE-5671 - remove internal flag and add API comments + * @public + * + * A custom destination for structured logging messages. */ export interface MongoDBLogWritable { + /** + * This function will be called for every enabled log message. + * + * It can be sync or async: + * - If it is synchronous it will block the driver from proceeding until this method returns. + * - If it is asynchronous the driver will not await the returned promise. It will attach fulfillment handling (`.then`). + * If the promise rejects the logger will write an error message to stderr and stop functioning. + * If the promise resolves the driver proceeds to the next log message (or waits for new ones to occur). + * + * Tips: + * - We recommend writing an async `write` function that _never_ rejects. + * Instead handle logging errors as necessary to your use case and make the write function a noop, until it can be recovered. + * - The Log messages are structured but **subject to change** since the intended purpose is informational. + * Program against this defensively and err on the side of stringifying whatever is passed in to write in some form or another. + * + */ write(log: Log): PromiseLike | unknown; } diff --git a/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts b/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts index ea909408318..7beac02a275 100644 --- a/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts +++ b/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts @@ -39,7 +39,6 @@ describe('Command Logging and Monitoring Prose Tests', function () { client = this.configuration.newClient( {}, { - __enableMongoLogger: true, mongodbLogPath: writable, mongodbLogComponentSeverities: { command: 'debug' @@ -123,7 +122,6 @@ describe('Command Logging and Monitoring Prose Tests', function () { client = this.configuration.newClient( {}, { - __enableMongoLogger: true, mongodbLogPath: writable, mongodbLogComponentSeverities: { command: 'debug' @@ -180,7 +178,6 @@ describe('Command Logging and Monitoring Prose Tests', function () { client = this.configuration.newClient( {}, { - __enableMongoLogger: true, mongodbLogPath: writable, mongodbLogComponentSeverities: { command: 'debug' diff --git a/test/integration/node-specific/abort_signal.test.ts b/test/integration/node-specific/abort_signal.test.ts index 8508aee0aa0..a7527479382 100644 --- a/test/integration/node-specific/abort_signal.test.ts +++ b/test/integration/node-specific/abort_signal.test.ts @@ -61,8 +61,7 @@ describe('AbortSignal support', () => { { monitorCommands: true, appName: 'abortSignalClient', - __enableMongoLogger: true, - __internalLoggerConfig: { MONGODB_LOG_SERVER_SELECTION: 'debug' }, + mongodbLogComponentSeverities: { serverSelection: 'debug' }, mongodbLogPath: { write: log => logs.push(log) }, serverSelectionTimeoutMS: 10_000, maxPoolSize: 1 @@ -629,8 +628,7 @@ describe('AbortSignal support', () => { client = this.configuration.newClient( {}, { - __enableMongoLogger: true, - __internalLoggerConfig: { MONGODB_LOG_SERVER_SELECTION: 'debug' }, + mongodbLogComponentSeverities: { serverSelection: 'debug' }, mongodbLogPath: { write: log => { if (log.c === 'serverSelection' && log.operation === 'ping') { @@ -675,8 +673,7 @@ describe('AbortSignal support', () => { connectStarted = promise.promise; client = this.configuration.newClient('mongodb://iLoveJavaScript', { - __enableMongoLogger: true, - __internalLoggerConfig: { MONGODB_LOG_SERVER_SELECTION: 'debug' }, + mongodbLogComponentSeverities: { serverSelection: 'debug' }, mongodbLogPath: { write: log => { if (log.c === 'serverSelection' && log.operation === 'ping') { diff --git a/test/integration/node-specific/mongo_client.test.ts b/test/integration/node-specific/mongo_client.test.ts index 3c4b776a825..4a97035d55c 100644 --- a/test/integration/node-specific/mongo_client.test.ts +++ b/test/integration/node-specific/mongo_client.test.ts @@ -16,7 +16,6 @@ import { MongoServerSelectionError, ReadPreference, ServerDescription, - SeverityLevel, Topology } from '../../mongodb'; import { runLater } from '../../tools/utils'; @@ -929,7 +928,7 @@ describe('class MongoClient', function () { }); const tests = [ - // only skipInitiaPing=true will have no events upon connect + // only skipInitialPing=true will have no events upon connect { description: 'should skip ping command when set to true', value: true, expectEvents: 0 }, { description: 'should not skip ping command when set to false', @@ -964,125 +963,5 @@ describe('class MongoClient', function () { }); } }); - - // TODO(NODE-5672): Release Standardized Logger - describe('__enableMongoLogger', () => { - let cachedEnv; - - before(() => { - cachedEnv = process.env; - }); - - after(() => { - process.env = cachedEnv; - }); - - context('when enabled', () => { - context('when logging is enabled for any component', () => { - before(() => { - process.env.MONGODB_LOG_COMMAND = SeverityLevel.EMERGENCY; - }); - - it('enables logging for the specified component', () => { - const client = new MongoClient('mongodb://localhost:27017', { - __enableMongoLogger: true - }); - expect(client.mongoLogger?.componentSeverities).to.have.property( - 'command', - SeverityLevel.EMERGENCY - ); - }); - }); - - context('when logging is not enabled for any component', () => { - before(() => { - process.env = {}; - }); - - it('does not create logger', () => { - const client = new MongoClient('mongodb://localhost:27017', { - __enableMongoLogger: true - }); - expect(client.mongoLogger).to.not.exist; - }); - }); - }); - - for (const optionValue of [false, undefined]) { - context(`when set to ${optionValue}`, () => { - context('when logging is enabled for a component', () => { - before(() => { - process.env['MONGODB_LOG_COMMAND'] = SeverityLevel.EMERGENCY; - }); - - it('does not instantiate logger', () => { - const client = new MongoClient('mongodb://localhost:27017', { - __enableMongoLogger: optionValue - }); - expect(client.mongoLogger).to.not.exist; - }); - }); - - context('when logging is not enabled for any component', () => { - before(() => { - process.env = {}; - }); - - it('does not instantiate logger', () => { - const client = new MongoClient('mongodb://localhost:27017', { - __enableMongoLogger: optionValue - }); - expect(client.mongoLogger).to.not.exist; - }); - }); - }); - } - }); - - describe('__internalLoggerConfig', () => { - let cachedEnv: NodeJS.ProcessEnv; - - before(() => { - cachedEnv = process.env; - }); - - after(() => { - process.env = cachedEnv; - }); - - context('when undefined', function () { - before(() => { - process.env.MONGODB_LOG_COMMAND = SeverityLevel.EMERGENCY; - }); - - it('falls back to environment options', function () { - const client = new MongoClient('mongodb://localhost:27017', { - __enableMongoLogger: true, - __internalLoggerConfig: undefined - }); - - expect(client.mongoLogger?.componentSeverities).to.have.property( - 'command', - SeverityLevel.EMERGENCY - ); - }); - }); - - context('when defined', function () { - it('overrides environment options', function () { - const client = new MongoClient('mongodb://localhost:27017', { - __enableMongoLogger: true, - __internalLoggerConfig: { - MONGODB_LOG_COMMAND: SeverityLevel.ALERT - } - }); - - expect(client.mongoLogger?.componentSeverities).to.have.property( - 'command', - SeverityLevel.ALERT - ); - }); - }); - }); }); }); diff --git a/test/tools/unified-spec-runner/entities.ts b/test/tools/unified-spec-runner/entities.ts index 04a6c6bc69c..4a5b7061547 100644 --- a/test/tools/unified-spec-runner/entities.ts +++ b/test/tools/unified-spec-runner/entities.ts @@ -210,21 +210,12 @@ export class UnifiedMongoClient extends MongoClient { this.buffer.push(transformedLog); } }; - const componentSeverities = { - MONGODB_LOG_ALL: 'off' - }; - - // NOTE: this is done to override the logger environment variables - for (const key in description.observeLogMessages) { - componentSeverities[UnifiedMongoClient.LOGGING_COMPONENT_TO_ENV_VAR_NAME[key]] = - description.observeLogMessages[key]; - } + const mongodbLogComponentSeverities = description.observeLogMessages; super(uri, { monitorCommands: true, __skipPingOnConnect: true, - __enableMongoLogger: true, - __internalLoggerConfig: componentSeverities, + mongodbLogComponentSeverities, ...getEnvironmentalOptions(), ...(description.serverApi ? { serverApi: description.serverApi } : {}), mongodbLogPath: logCollector, diff --git a/test/unit/connection_string.test.ts b/test/unit/connection_string.test.ts index f4a9591e038..744ed5e5213 100644 --- a/test/unit/connection_string.test.ts +++ b/test/unit/connection_string.test.ts @@ -850,9 +850,7 @@ describe('Connection String', function () { context('when option is `stderr`', function () { it('it is accessible through mongoLogger.logDestination', function () { - const client = new MongoClient('mongodb://a/?mongodbLogPath=stderr', { - __enableMongoLogger: true - }); + const client = new MongoClient('mongodb://a/?mongodbLogPath=stderr'); const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' }; client.options.mongoLoggerOptions.logDestination.write(log); const logLine = inspect(log, { breakLength: Infinity, compact: true }); @@ -862,9 +860,7 @@ describe('Connection String', function () { context('when option is `stdout`', function () { it('it is accessible through mongoLogger.logDestination', function () { - const client = new MongoClient('mongodb://a/?mongodbLogPath=stdout', { - __enableMongoLogger: true - }); + const client = new MongoClient('mongodb://a/?mongodbLogPath=stdout'); const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' }; client.options.mongoLoggerOptions.logDestination.write(log); const logLine = inspect(log, { breakLength: Infinity, compact: true }); @@ -874,10 +870,9 @@ describe('Connection String', function () { context('when option is invalid', function () { it('should throw error at construction', function () { - expect( - () => - new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', { __enableMongoLogger: true }) - ).to.throw(MongoAPIError); + expect(() => new MongoClient('mongodb://a/?mongodbLogPath=stdnothing')).to.throw( + MongoAPIError + ); }); }); }); @@ -919,7 +914,6 @@ describe('Connection String', function () { } }; new MongoClient(uri, { - __enableMongoLogger: true, mongodbLogPath: stream }); diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index f021448cd55..b24639f2c80 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -90,6 +90,7 @@ const EXPECTED_EXPORTS = [ 'MongoGridFSStreamError', 'MongoInvalidArgumentError', 'MongoKerberosError', + 'MongoLoggableComponent', 'MongoMissingCredentialsError', 'MongoMissingDependencyError', 'MongoNetworkError', @@ -102,11 +103,11 @@ const EXPECTED_EXPORTS = [ 'MongoServerClosedError', 'MongoServerError', 'MongoServerSelectionError', + 'MongoStalePrimaryError', 'MongoSystemError', 'MongoTailableCursorError', 'MongoTopologyClosedError', 'MongoTransactionError', - 'MongoStalePrimaryError', 'MongoUnexpectedServerResponseError', 'MongoWriteConcernError', 'ObjectId', @@ -129,6 +130,7 @@ const EXPECTED_EXPORTS = [ 'ServerSelectionStartedEvent', 'ServerSelectionSucceededEvent', 'ServerType', + 'SeverityLevel', 'SrvPollingEvent', 'Timestamp', 'TopologyClosedEvent', diff --git a/test/unit/mongo_client.test.ts b/test/unit/mongo_client.test.ts index 82669c1ce9d..fe8c2e034c0 100644 --- a/test/unit/mongo_client.test.ts +++ b/test/unit/mongo_client.test.ts @@ -846,7 +846,6 @@ describe('MongoClient', function () { context('when option is `stderr`', function () { it('it is accessible through mongoLogger.logDestination', function () { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogPath: 'stderr' }); const log = { t: new Date(), c: 'constructorStdErr', s: 'error' }; @@ -865,7 +864,6 @@ describe('MongoClient', function () { } }; const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogPath: writable }); expect(client.options.mongoLoggerOptions.logDestination).to.deep.equal(writable); @@ -875,7 +873,6 @@ describe('MongoClient', function () { context('when option is `stdout`', function () { it('it is accessible through mongoLogger.logDestination', function () { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogPath: 'stdout' }); const log = { t: new Date(), c: 'constructorStdOut', s: 'error' }; @@ -892,7 +889,6 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogPath: invalidOption }) ).to.throw(MongoAPIError); @@ -910,7 +906,6 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogPath: writable }) ).to.throw(MongoAPIError); @@ -931,9 +926,7 @@ describe('MongoClient', function () { }); it('should default to stderr', function () { - const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true - }); + const client = new MongoClient('mongodb://a/'); const log = { t: new Date(), c: 'constructorStdErr', s: 'error' }; client.options.mongoLoggerOptions.logDestination.write(log); const logLine = inspect(log, { breakLength: Infinity, compact: true }); @@ -956,7 +949,6 @@ describe('MongoClient', function () { it(`it stores severity levels for ${components[i]} component correctly`, function () { for (const severityLevel of Object.values(SeverityLevel)) { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { [components[i]]: severityLevel } @@ -980,7 +972,6 @@ describe('MongoClient', function () { process.env[env_component_names[i]] = 'emergency'; for (const severityLevel of Object.values(SeverityLevel)) { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { [components[i]]: severityLevel } @@ -1005,7 +996,6 @@ describe('MongoClient', function () { for (const severityLevel of Object.values(SeverityLevel)) { for (const defaultSeverityLevel of Object.values(SeverityLevel)) { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { [components[i]]: severityLevel, default: defaultSeverityLevel @@ -1030,7 +1020,6 @@ describe('MongoClient', function () { context('when invalid client option is provided', function () { const badClientCreator = () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { default: 'imFake' } @@ -1075,12 +1064,10 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: {} }) ).to.not.throw(MongoAPIError); const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { client: 'error' } // dummy so logger doesn't turn on }); expect(client.mongoLogger?.componentSeverities.command).to.equal('off'); @@ -1091,12 +1078,10 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { default: 'emergency' } }) ).to.not.throw(MongoAPIError); const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogComponentSeverities: { command: 'emergency' } }); expect(client.mongoLogger?.componentSeverities.command).to.equal('emergency'); @@ -1111,7 +1096,6 @@ describe('MongoClient', function () { context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided', function () { it('should store value for maxDocumentLength correctly', function () { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogMaxDocumentLength: 290 }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(290); @@ -1120,7 +1104,6 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogMaxDocumentLength: -290 }) ).to.throw(MongoParseError); @@ -1137,7 +1120,6 @@ describe('MongoClient', function () { it('should store value for maxDocumentLength correctly (client option value takes precedence)', function () { const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogMaxDocumentLength: 290 }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(290); @@ -1146,7 +1128,6 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - __enableMongoLogger: true, mongodbLogMaxDocumentLength: -290 }) ).to.throw(MongoParseError); @@ -1156,9 +1137,7 @@ describe('MongoClient', function () { context('when mongodbLogMaxDocumentLength is not in options', function () { context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided', function () { it('should store value for default maxDocumentLength correctly', function () { - const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true - }); + const client = new MongoClient('mongodb://a/'); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000); }); }); @@ -1169,17 +1148,13 @@ describe('MongoClient', function () { it('should store value for maxDocumentLength correctly', function () { process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH = '155'; - const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true - }); + const client = new MongoClient('mongodb://a/'); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(155); }); it('should not throw error for negative MONGODB_MAX_DOCUMENT_LENGTH and set to default', function () { process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH = '-14'; - const client = new MongoClient('mongodb://a/', { - __enableMongoLogger: true - }); + const client = new MongoClient('mongodb://a/'); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000); }); });