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

Python: Add basic logging, remove print statements, ... #2571

Open
AIexanderDicke opened this issue May 18, 2024 · 1 comment
Open

Python: Add basic logging, remove print statements, ... #2571

AIexanderDicke opened this issue May 18, 2024 · 1 comment

Comments

@AIexanderDicke
Copy link

At the moment, the python library has no logging. Errors are simply printed to stdout (e.g. here or here). This makes it very difficult to monitor an application that uses BullMQ.

Some examples of logs to add (always assuming logger = logging.getLogger(__name__)):

  1. Remove the printing of exceptions and instead log on error level. For example, change this line to something like
logging.error(f"Error processing job {repr(err)}")

Even better might be something more informative like

logging.error(f"Error processing Job (Worker: `{self.name}`, Job ID: `{job.id}`, Queue name: {job.queue.name}): {repr(err)})
  1. Add basic job logging on info (or maybe debug) level, e.g. by adding something like
logger.info(f"Processing Job (Job ID: `{job.id}`, Queue name: {job.queue.name})")

to the Worker.processJob method.

  1. Add logs for adding jobs to a queue, maybe something along the lines of
logger.info(f"Job added to the queue `{self.name}` (Job ID: {job_id})") 

I would be happy to implement this, if there are no objections to these changes!

@manast
Copy link
Contributor

manast commented May 23, 2024

Thanks for your proposal. I think that in general it is better to leave the logging to the client of the library, for example listening to the proper events you should be able to produce the logs for those things that you are interested of. The reason being that some users may not want to spend time calling a log function if they want to maximize performance. The examples that you pointed out I think should actually be removed as I can see we are emitting an error when they happen. It is probably the left-overs of some debugging which was overlooked when reviewing a PR. A middle ground could be to have a special pluggable Logger functionality that can be attached to a Worker or Queue class and listens to the events and output logs, in this way it could be choosen by the user when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants