Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-4992): Deprecate methods and options that reference legacy logger #3532

Merged
merged 15 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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