From 504ff25d68ebbbe08a1b1747601d9eb8eeac6271 Mon Sep 17 00:00:00 2001 From: Abhinav kumar <126642111+Abhinavcode13@users.noreply.github.com> Date: Sun, 26 May 2024 09:26:07 +0530 Subject: [PATCH] Added exception logging with stack trace --- src/polyphy/utils/logger.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/polyphy/utils/logger.py b/src/polyphy/utils/logger.py index dbbfe78..98111c4 100644 --- a/src/polyphy/utils/logger.py +++ b/src/polyphy/utils/logger.py @@ -61,3 +61,17 @@ def logToFile(level, *msg) -> None: Logger.file_logger.setLevel(Logger.log_level.get(level, logging.INFO)) res = " ".join(map(str, msg)) Logger.file_log_functions.get(level, Logger.file_logger.info)(res) + + @staticmethod + def logException(level, exception, *msg) -> None: + + # Construct log message with exception info + log_msg = " ".join(map(str, msg)) + log_msg += f"\nException: {repr(exception)}" + log_msg += f"\nStack Trace: {traceback.format_exc()}" + + # Log to console + Logger.logToStdOut(level, log_msg) + + # Log to file + Logger.logToFile(level, log_msg)