Skip to content

`log_slow_callbacks.enable` now accepts an optional custom logging callback

log_slow_callbacks.enable now accepts an optional callback that, if provided, will be called instead of the default logger.warning.

Proposed in https://github.com/qntln/aiodebug/issues/3:

I'd like to use this module for JSON logging when an async task blocks the async loop for too long. It'd be nice to have an API that allows users to call a custom callback when a task takes too long to run. For example:

aiodebug.log_slow_callbacks.enable(
 0.05,
 callback=lambda duration:
   json_logger.warning("Task blocked async loop for too long", extra={"duration": duration})
)

The actual implementation looks like this:

aiodebug.log_slow_callbacks.enable(
  0.05,
  on_slow_callback=lambda task_name, duration:
    json_logger.warning("Task blocked async loop for too long", extra={"task_name": task_name, "duration": duration})
)

Merge request reports

Loading