Skip to content

Commit

Permalink
Added exception logging with stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinavcode13 authored May 26, 2024
1 parent acfbd7f commit 504ff25
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/polyphy/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 504ff25

Please sign in to comment.