From 577f9593130b40a48ca4bdac2d3660ebdcc3ae27 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 2 May 2024 15:02:04 +0100 Subject: [PATCH] continue adding helper functions. --- datashuttle/utils/ds_logger.py | 7 ++++++- datashuttle/utils/utils.py | 17 ++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/datashuttle/utils/ds_logger.py b/datashuttle/utils/ds_logger.py index 79babd67..6631cfd7 100644 --- a/datashuttle/utils/ds_logger.py +++ b/datashuttle/utils/ds_logger.py @@ -26,7 +26,11 @@ def get_logger(): def logging_is_active(): - return get_logger_name() in logging.root.manager.loggerDict + logger_exists = get_logger_name() in logging.root.manager.loggerDict + if logger_exists: + if get_logger().handlers != []: + return True + return False def start( @@ -109,6 +113,7 @@ def close_log_filehandler() -> None: Remove handlers from all loggers. """ logger = get_logger() + logger.debug("Finished logging.") handlers = logger.handlers[:] for handler in handlers: logger.removeHandler(handler) diff --git a/datashuttle/utils/utils.py b/datashuttle/utils/utils.py index 02df6acb..296f3777 100644 --- a/datashuttle/utils/utils.py +++ b/datashuttle/utils/utils.py @@ -25,7 +25,6 @@ def log(message: str) -> None: """ if ds_logger.logging_is_active(): logger = ds_logger.get_logger() - breakpoint() logger.debug(message) @@ -49,6 +48,14 @@ def log_and_raise_error(message: str, exception: Any) -> None: raise_error(message, exception) +def warn(message: str, log: bool) -> None: + """ """ + if log and ds_logger.logging_is_active(): + logger = ds_logger.get_logger() + logger.warning(message) + warnings.warn(message) + + def raise_error(message: str, exception) -> None: """ Centralized way to raise an error. The logger is closed @@ -59,14 +66,6 @@ def raise_error(message: str, exception) -> None: raise exception(message) -def warn(message: str, log: bool) -> None: - """ """ - if log and ds_logger.logging_is_active(): - logger = ds_logger.get_logger() - logger.warning(message) - warnings.warn(message) - - def print_message_to_user( message: Union[str, list], use_rich: bool = False ) -> None: