Fix logs output

This commit is contained in:
Kiryl
2022-11-16 14:40:28 +03:00
parent b2491d0195
commit 58e2c74014
6 changed files with 104 additions and 103 deletions

View File

@@ -15,30 +15,30 @@ from src.docx_converter.docx_solver import DocxBook
from src.epub_converter.epub_solver import EpubBook
def local_convert_book(book_type: [DocxBook, EpubBook], book_id: int, logger: logging.Logger, params: dict):
logger.info(f"Start processing book-{book_id}.")
def local_convert_book(book_type: [DocxBook, EpubBook], book_id: int, main_logger: logging.Logger, params: dict):
main_logger.info(f"Start processing book-{book_id}.")
try:
json_file_path = "books/json/9781614382264.json"
book = book_type(book_id=book_id, main_logger=logger, **params)
book = book_type(book_id=book_id, main_logger=main_logger, **params)
book.conversion(json_file_path)
except Exception as exc:
raise exc
logger.info(f"Book-{book_id} has been proceeded.")
main_logger.info(f"Book-{book_id} has been proceeded.")
def convert_book(book_type: [DocxBook, EpubBook], book_id: int, logger: logging.Logger, params: Dict[str, Access]):
logger.info(f"Start processing book-{book_id}.")
def convert_book(book_type: [DocxBook, EpubBook], book_id: int, main_logger: logging.Logger, params: Dict[str, Access]):
main_logger.info(f"Start processing book-{book_id}.")
try:
book = book_type(book_id=book_id, main_logger=logger, **params)
book = book_type(book_id=book_id, main_logger=main_logger, **params)
book.conversion()
except Exception as exc:
raise exc
logger.info(f"Book-{book_id} has been proceeded.")
main_logger.info(f"Book-{book_id} has been proceeded.")
def callback(ch, method, properties, body: bytes, logger: logging.Logger, libre_locker: Event):
def callback(ch, method, properties, body: bytes, main_logger: logging.Logger, libre_locker: Event):
print(f"Message: {body}.")
logger.info(f"Message: {body}.")
main_logger.info(f"Message: {body}.")
try:
data = json.loads(body)
assert "apiURL" in data, "No apiURL field in received message."
@@ -54,7 +54,7 @@ def callback(ch, method, properties, body: bytes, logger: logging.Logger, libre_
params = {
"book_type": EpubBook if data.get("fileExtension") == "epub" else DocxBook,
"book_id": data["id"],
"logger": logger,
"main_logger": main_logger,
"params": book_params
}
@@ -64,9 +64,9 @@ def callback(ch, method, properties, body: bytes, logger: logging.Logger, libre_
# print(f"Active threads: {active_count()}.")
except Exception as exc:
if hasattr(exc, "message"):
logger.error(f"{sys.exc_info()[0]}: {exc.message}")
main_logger.error(f"{sys.exc_info()[0]}: {exc.message}")
else:
logger.error(f"{sys.exc_info()[0]}: {str(exc)}")
main_logger.error(f"{sys.exc_info()[0]}: {str(exc)}")
finally:
pass
@@ -104,7 +104,7 @@ def server_run():
locker.set()
channel.basic_consume(queue=conf_param["queue"],
auto_ack=True,
on_message_callback=partial(callback, logger=logger_object, libre_locker=locker))
on_message_callback=partial(callback, main_logger=logger_object, libre_locker=locker))
logger_object.info("Connection has been established.")
print("Waiting for messages...")
logger_object.info("Waiting for messages...")