#17 - review log message, standartize format and add location info

This commit was merged in pull request #19.
This commit is contained in:
Stanislav Hejny
2025-04-24 02:34:11 +01:00
parent d4d633cb46
commit 88d45a9b67
14 changed files with 243 additions and 158 deletions
+24 -19
View File
@@ -5,7 +5,12 @@ from aio_pika.abc import AbstractRobustQueue, AbstractRobustExchange
from pika.exchange_type import ExchangeType
from amqp.adapter.data_message_factory import DataMessageFactory
from amqp.adapter.logging_utils import logging_error
from amqp.adapter.logging_utils import (
logging_error,
logging_debug,
logging_info,
logging_warning,
)
from amqp.model.model import DataMessage, AMQRoute
from amqp.router.router_base import (
AMQ_REPLY_TO_EXCHANGE,
@@ -28,7 +33,7 @@ class RabbitMQClient:
self.amq_configuration = configuration
logging.info("*******************************************")
logging.info(
"******** RabbitMQProducer.init(): %s",
"******** RabbitMQClient.init(): %s",
self.amq_configuration.dispatch.amq_host,
)
logging.info("*******************************************")
@@ -58,7 +63,7 @@ class RabbitMQClient:
return self.reply_to_exchange
def cleanup(self):
logging.info(" [*] RabbitMQClient.cleanup()")
logging_info("RabbitMQClient.cleanup()")
self.router.cleanup() # de-register route(s)
if self.router.is_open(self.channel):
try:
@@ -67,7 +72,7 @@ class RabbitMQClient:
self.connection.close()
except Exception as e:
logging_error(
" [E] RabbitMQClient.PreDestroy cleanup - connection close error: %s",
"RabbitMQClient.PreDestroy cleanup - connection close error: %s",
e,
)
@@ -83,8 +88,8 @@ class RabbitMQClient:
queue_args = (
self.DLQ_ARGS if self.amq_configuration.dispatch.use_dlq else None
)
logging.info(
" [*] RabbitMQClient register routes, cfg mapping: [%s]", route_mapping
logging_info(
"RabbitMQClient register routes, cfg mapping: [%s]", route_mapping
)
# convert the comma-separated string into list of AMQRoute objects
requested_routes = self.router.unwrap_route_list(route_mapping)
@@ -96,7 +101,7 @@ class RabbitMQClient:
if route.queue
else self.router.get_consume_queue_name()
)
logging.info(" [*] RabbitMQClient register route: [%s]", route)
logging_info("RabbitMQClient register route: [%s]", route)
queue: AbstractRobustQueue = await self.channel.declare_queue(
name=queue_name,
durable=True,
@@ -125,7 +130,7 @@ class RabbitMQClient:
route.valid_until,
)
)
logging.info(
logging_info(
" [%s] AMQ connection initialized for route: %s, listens on: %s/%s",
_c_tag,
route,
@@ -135,11 +140,11 @@ class RabbitMQClient:
except Exception as err:
logging_error("Callback registration INCOMPLETE, %s", err)
else:
logging.warning(" [W] Channel is null, cannot register routes.")
logging_warning("Channel is null, cannot register routes.")
async def register_data_reply_callback(self, rpc_callback):
_c_tag = await self.reply_to_queue.consume(callback=rpc_callback, no_ack=False)
logging.info(
logging_info(
" [%s] RabbitMQClient register data reply callback on queue: %s",
_c_tag,
self.reply_to_queue.name,
@@ -157,16 +162,16 @@ class RabbitMQClient:
password=self.amq_configuration.dispatch.rabbit_mq_password,
loop=loop,
)
logging.info(
"RabbitMQProducer.setupAMQ, got connection, open=%s",
logging_debug(
"RabbitMQClient.setupAMQ, got connection, open=%s",
self.connection.is_closed,
)
self.channel = await self.connection.channel()
await self.channel.set_qos(prefetch_count=self.PREFETCH_COUNT)
await self.router.init_internal_routing_paths(self.channel)
self.router.set_route_added_notifier(
lambda route: logging.info(
" [DBG] ---------- RouteAdded, setting up metrics: amqp.adapter.exchange.%s",
lambda route: logging_debug(
" RouteAdded, setting up metrics: amqp.adapter.exchange.%s",
route.exchange,
)
)
@@ -195,8 +200,8 @@ class RabbitMQClient:
message
), # context path is a routing key
)
logging.info(
f" [x] basicPublish (no-reply), messageId: {message.id}, to: {route}"
logging_info(
f"Msg Publish (no-reply), messageId: {message.id}, to: {route}"
)
else:
# This is RPC call, there should be response
@@ -213,13 +218,13 @@ class RabbitMQClient:
message
), # context path is a routing key
)
logging.info(
" [x] basicPublish (RPC call), messageId: %s, to: %s",
logging_info(
"Msg Publish (RPC call), messageId: %s, to: %s",
message.id.as_string(),
route.as_string(),
)
else:
logging.warning(
logging_warning(
"Message not sent, no route for %s/%s", message.domain, message.path
)