Skip to content

Commit

Permalink
Merge pull request #87 from MolarVerse/hotfix/1.0.10
Browse files Browse the repository at this point in the history
fix: logger now working again also for cli tools
  • Loading branch information
97gamjak authored May 31, 2024
2 parents 5b434d6 + e101a7b commit 7f32b4b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions PQAnalysis/utils/custom_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ class CustomLogger(logging.Logger):
and original_critical methods can be used.
"""

def _log(self, # pylint: disable=arguments-differ
level: Any,
msg: Any,
args: Any,
exception: Exception | None = None,
**kwargs
) -> None:
def _log(
self, # pylint: disable=arguments-differ
level: Any,
msg: Any,
args: Any,
exception: Exception | None = None,
**kwargs
) -> None:
"""
This method is a wrapper method for the original _log method of the logging.Logger class.
Expand Down Expand Up @@ -147,19 +148,14 @@ def exception_hook(exc_type, exc_value, exc_traceback):
"""
A custom exception hook that ignores the CustomLoggerException.
"""
if exc_type != PQException:
if isinstance(exc_type, PQException):
sys.__excepthook__(exc_type, exc_value, exc_traceback)

sys.excepthook = exception_hook
raise exception(msg) # pylint: disable=broad-exception-raised

def _original_log(
self,
level: Any,
msg: Any,
args: Any,
extra=None,
**kwargs
self, level: Any, msg: Any, args: Any, extra=None, **kwargs
) -> None:
"""
The original _log method of the logging.Logger class.
Expand Down Expand Up @@ -355,8 +351,8 @@ def format(self, record: logging.LogRecord) -> str:

messages = message.split('\n')
wrapper = textwrap.TextWrapper(
width=shutil.get_terminal_size(fallback=(80,
100)).columns - len(level),
width=shutil.get_terminal_size(fallback=(80, 100)).columns -
len(level),
initial_indent=' ' * (len(longest_level_key) + 2),
subsequent_indent=' ' * (len(longest_level_key) + 2),
)
Expand Down

0 comments on commit 7f32b4b

Please sign in to comment.