python-logging-rabbitmq icon indicating copy to clipboard operation
python-logging-rabbitmq copied to clipboard

Issue/43 add amqp url

Open jfgrea27 opened this issue 1 year ago • 0 comments

Issue 43: RabbitMQHandler should be able to connect via a AMQP URL with URLParameters

This PR:

  • Allows for url parameter in RabbitMQHandler & RabbitMQHandlerOneWay constructor to connect to pika connection via AMQP URI.
  • Updates to README.md with examples.

Tested by:

  • Running local logger against a CloudAMQP instance with/out url.

Example Test:

import logging
from python_logging_rabbitmq import RabbitMQHandler
DEFAULT_LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

logger = logging.getLogger(__name__)
formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
rabbit_handler = RabbitMQHandler(
    url="...",
    exchange="...",
    routing_key_format="..."
)

rabbit_handler.setFormatter(formatter)
rabbit_handler.setLevel("INFO")
logger.addHandler(rabbit_handler)

logger.info("With url")

rabbit_handler = RabbitMQHandler(
    host="...",
    port=5672,
    username="...",
    password="...",
    connection_params={
	'virtual_host': '...',
    },
    exchange="...",
    routing_key_format="..."
)

rabbit_handler.setFormatter(formatter)
rabbit_handler.setLevel("INFO")
logger.addHandler(rabbit_handler)

logger.info("Without url")

jfgrea27 avatar Feb 13 '24 16:02 jfgrea27