Skip to content

Commit

Permalink
Merge pull request #58 from bringg/delete_deperecated_logger
Browse files Browse the repository at this point in the history
Delete deprecated transport option.
  • Loading branch information
ramhr committed Apr 13, 2023
2 parents 694af2c + 93e981f commit 21a7859
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 35 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ const arnavmq = require('arnavmq')({
// generate a hostname so we can track this connection on the broker (rabbitmq management plugin)
hostname: process.env.HOSTNAME || process.env.USER || uuid.v4(),

// Deprecated. Use 'logger' instead. The transport to use to debug. If provided, arnavmq will show some logs
transport: utils.emptyLogger,

/**
* A logger object with a log function for each of the log levels ("debug", "info", "warn", or "error").
* Each log function receives one parameter containing a log event with the following fields:
Expand All @@ -153,7 +150,7 @@ const arnavmq = require('arnavmq')({

You can override any or no of the property above.

**Note:** if you enable the debug mode using the `AMQP_DEBUG=true` env var, but you do not attach any transport logger, the module will fallback to console.
**Note:** if you enable the debug mode using the `AMQP_DEBUG=true` env var, but you do not attach any logger, the module will fallback to console.

## Documentation & resources

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arnavmq",
"version": "0.14.1",
"version": "0.15.0",
"description": "ArnavMQ is a RabbitMQ wrapper",
"keywords": [
"rabbitmq",
Expand Down
10 changes: 2 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ module.exports = (config) => {
// generate a hostname so we can track this connection on the broker (rabbitmq management plugin)
hostname: process.env.HOSTNAME || process.env.USER || uuid.v4(),

// Deprecated. Use 'logger' instead. The transport to use to debug. If provided, arnavmq will show some logs
transport: utils.emptyLogger,

/**
* A logger object with a log function for each of the log levels ("debug", "info", "warn", or "error").
* Each log function receives one parameter containing a log event with the following fields:
Expand All @@ -45,11 +42,8 @@ module.exports = (config) => {
...config,
};

if (configuration.transport !== utils.emptyLogger) {
process.emitWarning(
"The 'transport' configuration option is deprecated. Please use the 'logger' option instead.",
'DeprecationWarning'
);
if (configuration.transport) {
throw new Error('Using removed deprecated "transport" option. Use the "logger" option instead.');
}

configuration.prefetch = parseInt(configuration.prefetch, 10) || 0;
Expand Down
1 change: 0 additions & 1 deletion src/modules/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Connection {
* @param {Error} error
*/
_onError(error) {
this._config.transport.error(error);
this._config.logger.error({
message: error.message,
error,
Expand Down
10 changes: 0 additions & 10 deletions src/modules/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Consumer {
persistent: true,
durable: true,
};
this._connection.config.transport.debug(loggerAlias, `[${queue}][${messageProperties.replyTo}] >`, reply);
this._connection.config.logger.debug({
message: `${loggerAlias} [${queue}][${messageProperties.replyTo}] > ${reply}`,
params: { content: reply },
Expand Down Expand Up @@ -96,15 +95,13 @@ class Consumer {
try {
await channel.assertQueue(suffixedQueue, options);
} catch (error) {
this._connection.config.transport.error(loggerAlias, error);
this._connection.config.logger.error({
message: `${loggerAlias} Failed to assert queue ${queue}: ${error.message}`,
error,
params: { queue },
});
}

this._connection.config.transport.debug(loggerAlias, 'init', queue);
this._connection.config.logger.debug({
message: `${loggerAlias} init ${queue}`,
params: { queue },
Expand Down Expand Up @@ -133,7 +130,6 @@ class Consumer {
// Just in the odd chance the channel was open but the listener failed.
await channel.close();
} catch (closeError) {
this._connection.config.transport.error(loggerAlias, closeError);
this._connection.config.logger.error({
message: `${loggerAlias} Failed to close channel after initialization error ${queue}: ${closeError.message}`,
error: closeError,
Expand All @@ -150,7 +146,6 @@ class Consumer {
if (!msg) {
// When forcefully cancelled by rabbitmq, consumer would receive a null message.
// https://amqp-node.github.io/amqplib/channel_api.html#channel_consume
this._connection.config.transport.warn(loggerAlias, null);
this._connection.config.logger.warn({
message: `${loggerAlias} Consumer was cancelled by server for queue '${queue}'`,
error: null,
Expand All @@ -160,7 +155,6 @@ class Consumer {
}

const messageString = msg.content.toString();
this._connection.config.transport.debug(loggerAlias, `[${queue}] < ${messageString}`);
this._connection.config.logger.debug({
message: `${loggerAlias} [${queue}] < ${messageString}`,
params: { queue, message: messageString },
Expand All @@ -174,7 +168,6 @@ class Consumer {
await this.checkRpc(msg.properties, queue, res);
} catch (error) {
// if something bad happened in the callback, reject the message so we can requeue it (or not)
this._connection.config.transport.error(loggerAlias, error);
this._connection.config.logger.error({
message: `${loggerAlias} Failed processing message from queue ${queue}: ${error.message}`,
error,
Expand All @@ -184,7 +177,6 @@ class Consumer {
try {
channel.reject(msg, this._connection.config.requeue);
} catch (rejectError) {
this._connection.config.transport.error(loggerAlias, rejectError);
this._connection.config.logger.error({
message: `${loggerAlias} Failed to reject message after processing failure on queue ${queue}: ${rejectError.message}`,
error: rejectError,
Expand All @@ -198,7 +190,6 @@ class Consumer {
try {
channel.ack(msg);
} catch (ackError) {
this._connection.config.transport.error(loggerAlias, ackError);
this._connection.config.logger.error({
message: `${loggerAlias} Failed to ack message after processing finished on queue ${queue}: ${ackError.message}`,
error: ackError,
Expand All @@ -210,7 +201,6 @@ class Consumer {
try {
await channel.consume(queue, consumeFunc, { noAck: false });
} catch (error) {
this._connection.config.transport.error(loggerAlias, error);
this._connection.config.logger.error({
message: `${loggerAlias} Failed to start consuming from queue ${queue}: ${error.message}`,
error,
Expand Down
4 changes: 0 additions & 4 deletions src/modules/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Producer {
// On timeout the waiter is deleted, so we need to handle the race when the response arrives too late.
if (responsePromise === undefined) {
const error = new Error(`Receiving RPC message from previous session: callback no more in memory. ${queue}`);
this._connection.config.transport.warn(loggerAlias, error);
this._connection.config.logger.warn({
message: `${loggerAlias} ${error.message}`,
error,
Expand All @@ -61,7 +60,6 @@ class Producer {
}

// if we found one, we execute the callback and delete it because it will never be received again anyway
this._connection.config.transport.info(loggerAlias, `[${queue}] < answer`);
this._connection.config.logger.debug({
message: `${loggerAlias} [${queue}] < answer`,
params: { queue },
Expand Down Expand Up @@ -228,7 +226,6 @@ class Producer {
message = null;
}

this._connection.config.transport.info(loggerAlias, `[${queue}] > `, message);
this._connection.config.logger.debug({
message: `${loggerAlias} [${queue}] > ${message}`,
params: { queue, message },
Expand All @@ -242,7 +239,6 @@ class Producer {
}

// add timeout between retries because we don't want to overflow the CPU
this._connection.config.transport.error(loggerAlias, error);
this._connection.config.logger.error({
message: `${loggerAlias} Failed sending message to queue ${queue}: ${error.message}`,
error,
Expand Down
8 changes: 1 addition & 7 deletions src/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ const emptyLogger = {

module.exports = {
/**
* Default transport to prevent any printing in the terminal
* Default logger to prevent any printing in the terminal
* @type {Object} - empty logger overwriting the console object methods
*/
emptyLogger,

/**
* @deprecated
* For backwards compatibility with the `transport` configuration.
*/
emptyTransport: emptyLogger,

/**
* A function to generate a pause in promise chaining
* @param {number} timer How much ws to wait
Expand Down

0 comments on commit 21a7859

Please sign in to comment.