Skip to content

RabbitMQ

RabbitMQHandler publishes log entries to a RabbitMQ queue using pika. Connections are established lazily on first write.

Installation

No additional dependencies required. This integration uses Python's standard library.

Usage

python
from logly import logger
from logly.integrations.rabbitmq import RabbitMQHandler

handler = RabbitMQHandler(
    "amqp://guest:guest@localhost:5672/",
    queue="app-logs",
)
logger.add(handler, level="WARNING")

Constructor Args

ArgumentTypeDefaultDescription
urlstramqp://guest:guest@localhost:5672/RabbitMQ connection URL
queuestrlogly-logsQueue name to publish messages to
exchangestr""Exchange name (empty string for default exchange)
routing_keystr | NoneNoneRouting key (defaults to queue name)
durableboolTrueWhether the queue/exchange should survive restarts
timeoutfloat5.0Connection timeout in seconds

Tips

  • Use durable=True (default) so log messages survive RabbitMQ restarts.
  • Use a dedicated exchange and routing key for log routing in complex topologies.

Full Example

python
from logly import logger
from logly.integrations.rabbitmq import RabbitMQHandler

handler = RabbitMQHandler(
    url="amqp://user:pass@rabbit-host:5672/",
    queue="production-logs",
    exchange="logs",
    routing_key="app.logs",
    durable=True,
    timeout=10.0,
)
logger.add(handler, level="WARNING")

logger.warning("Queue depth high", queue="orders", depth=5000)
logger.error("Consumer lag detected", consumer="worker-3")

Released under the MIT License.