debug library not working in conjunction with amqplib (rabbitmq)

520 Views Asked by At

We run our app in two "modes":

  1. Our REST API (express js)
  2. Our background processor (amqplib)

Our REST API that starts using nodemon runs completely fine with debug, however our background processor does not work with debug.

We declare DEBUG=app:* in our .env file and yes, we do see it when we console log but for some reason when we do the following, nothing reports when running our background processor.

We do see that one of amqp's dependencies called bitsyntax uses debug. I am wondering if it does anything to turn off debug but cannot find anything in their code that does that.

Is there anything I can do to resolve this problem?

import amqp from 'amqplib/callback_api'
import dotenv from 'dotenv'
import debug from 'debug'

const testLog = debug('app:worker')

const rabbitmq = `amqp://${process.env.RABBITMQ_USER}:${process.env.RABBITMQ_PASS}@${process.env.RABBITMQ_HOST}`
console.log(process.env.DEBUG) // app:*
const worker = () => {
  try {
    amqp.connect(rabbitmq, (err, conn) => {
      // ...
      testLog('this does not show up')
      console.log('this does show up')
      // ...
    })
  } catch (err) {
    // ...
  }
}

worker()

We run our background processor using the following command: NODE_ENV=development nodemon ./src/workers/index.ts

1

There are 1 best solutions below

0
On

As per the following github issue response, on workers the following code needs to be enabled:

debug.enable(process.env.DEBUG)