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 1/4] 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) From b6852e04f739031f58d5bc85438b330a66f55c42 Mon Sep 17 00:00:00 2001 From: Abhinav kumar <126642111+Abhinavcode13@users.noreply.github.com> Date: Sun, 26 May 2024 09:31:32 +0530 Subject: [PATCH 2/4] Format indent --- src/polyphy/utils/logger.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/polyphy/utils/logger.py b/src/polyphy/utils/logger.py index 98111c4..93e1f28 100644 --- a/src/polyphy/utils/logger.py +++ b/src/polyphy/utils/logger.py @@ -6,6 +6,7 @@ from datetime import datetime import logging import time +from logging.handlers import RotatingFileHandler class Logger: @@ -45,6 +46,7 @@ def logToStdOut(level, *msg) -> None: # FILE: file_logger = logging.getLogger("file") file_handler = logging.FileHandler("polyphy.log") + file_handler = RotatingFileHandler("polyphy.log", maxBytes=1024*1024, backupCount=3) file_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") file_handler.setFormatter(file_formatter) file_logger.addHandler(file_handler) @@ -64,14 +66,12 @@ def logToFile(level, *msg) -> None: @staticmethod def logException(level, exception, *msg) -> None: + log_msg = " ".join(map(str, msg)) + log_msg += f"\nException: {repr(exception)}" + log_msg += f"\nStack Trace: {traceback.format_exc()}" - # 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) + # Log to console + Logger.logToStdOut(level, log_msg) + + # Log to file + Logger.logToFile(level, log_msg) From c8ad2543390f12008cea187614e9edb94ad3eb19 Mon Sep 17 00:00:00 2001 From: Abhinav kumar <126642111+Abhinavcode13@users.noreply.github.com> Date: Sun, 26 May 2024 09:34:27 +0530 Subject: [PATCH 3/4] Import traceback --- src/polyphy/utils/logger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/polyphy/utils/logger.py b/src/polyphy/utils/logger.py index 93e1f28..600521c 100644 --- a/src/polyphy/utils/logger.py +++ b/src/polyphy/utils/logger.py @@ -6,6 +6,7 @@ from datetime import datetime import logging import time +import traceback from logging.handlers import RotatingFileHandler From 1c61fb3a64763d2a9deb11a6890d8bcd21d0326c Mon Sep 17 00:00:00 2001 From: Abhinav kumar <126642111+Abhinavcode13@users.noreply.github.com> Date: Sun, 26 May 2024 09:39:26 +0530 Subject: [PATCH 4/4] Remove blankspace --- src/polyphy/utils/logger.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/polyphy/utils/logger.py b/src/polyphy/utils/logger.py index 600521c..98b5517 100644 --- a/src/polyphy/utils/logger.py +++ b/src/polyphy/utils/logger.py @@ -70,9 +70,7 @@ def logException(level, exception, *msg) -> None: 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)