Skip to content

Commit

Permalink
feat(NODE-4992): Deprecate methods and options that reference legacy …
Browse files Browse the repository at this point in the history
…logger (#3532)
  • Loading branch information
W-A-James committed Jan 25, 2023
1 parent 4c49b2e commit 6c94b4a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 25 deletions.
6 changes: 5 additions & 1 deletion src/db.ts
Expand Up @@ -774,11 +774,15 @@ export class Db {
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
}

/** Return the db logger */
/**
* Return the db logger
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
getLogger(): Logger {
return this.s.logger;
}

/** @deprecated The Legacy Logger is deprecated and will be removed in the next major version. */
get logger(): Logger {
return this.s.logger;
}
Expand Down
36 changes: 20 additions & 16 deletions src/gridfs/download.ts
Expand Up @@ -12,7 +12,7 @@ import {
import type { FindOptions } from '../operations/find';
import type { ReadPreference } from '../read_preference';
import type { Sort } from '../sort';
import type { Callback } from '../utils';
import { Callback, maybeCallback } from '../utils';
import type { GridFSChunk } from './upload';

/** @public */
Expand Down Expand Up @@ -185,22 +185,26 @@ export class GridFSBucketReadStream extends Readable implements NodeJS.ReadableS
*
* @param callback - called when the cursor is successfully closed or an error occurred.
*/
abort(callback?: Callback<void>): void {
this.push(null);
this.destroyed = true;
if (this.s.cursor) {
this.s.cursor.close(error => {
this.emit(GridFSBucketReadStream.CLOSE);
callback && callback(error);
});
} else {
if (!this.s.init) {
// If not initialized, fire close event because we will never
// get a cursor
this.emit(GridFSBucketReadStream.CLOSE);
abort(): Promise<void>;
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
abort(callback: Callback<void>): void;
abort(callback?: Callback<void>): Promise<void> | void {
return maybeCallback(async () => {
this.push(null);
this.destroyed = true;
if (this.s.cursor) {
await this.s.cursor.close().catch(error => {
this.emit(GridFSBucketReadStream.CLOSE);
throw error;
});
} else {
if (!this.s.init) {
// If not initialized, fire close event because we will never
// get a cursor
this.emit(GridFSBucketReadStream.CLOSE);
}
}
callback && callback();
}
}, callback);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/gridfs/index.ts
Expand Up @@ -226,7 +226,11 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
}, callback);
}

/** Get the Db scoped logger. */
/**
* Get the Db scoped logger.
*
* @deprecated Legacy Logger is deprecated and will be removed in the next major version.
*/
getLogger(): Logger {
return this.s.db.s.logger;
}
Expand Down
20 changes: 16 additions & 4 deletions src/logger.ts
Expand Up @@ -15,7 +15,10 @@ const pid = process.pid;
// eslint-disable-next-line no-console
let currentLogger: LoggerFunction = console.warn;

/** @public */
/**
* @public
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
export const LoggerLevel = Object.freeze({
ERROR: 'error',
WARN: 'warn',
Expand All @@ -27,13 +30,22 @@ export const LoggerLevel = Object.freeze({
debug: 'debug'
} as const);

/** @public */
/**
* @public
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
export type LoggerLevel = typeof LoggerLevel[keyof typeof LoggerLevel];

/** @public */
/**
* @public
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
export type LoggerFunction = (message?: any, ...optionalParams: any[]) => void;

/** @public */
/**
* @public
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
export interface LoggerOptions {
logger?: LoggerFunction;
loggerLevel?: LoggerLevel;
Expand Down
16 changes: 13 additions & 3 deletions src/mongo_client.ts
Expand Up @@ -233,9 +233,15 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
* @deprecated Setting a custom promise library is deprecated the next major version will use the global Promise constructor only.
*/
promiseLibrary?: any;
/** The logging level */
/**
* The logging level
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
loggerLevel?: LegacyLoggerLevel;
/** Custom logger object */
/**
* Custom logger object
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
logger?: LegacyLogger;
/** Enable command monitoring for this client */
monitorCommands?: boolean;
Expand Down Expand Up @@ -421,6 +427,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
return this.s.bsonOptions;
}

/** @deprecated The Legacy Logger is deprecated and will be removed in the next major version. */
get logger(): LegacyLogger {
return this.s.logger;
}
Expand Down Expand Up @@ -711,7 +718,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
}

/** Return the mongo client logger */
/**
* Return the mongo client logger
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
*/
getLogger(): LegacyLogger {
return this.s.logger;
}
Expand Down

0 comments on commit 6c94b4a

Please sign in to comment.