Skip to content

Commit

Permalink
continue adding helper functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZiminski committed May 2, 2024
1 parent 4b96f65 commit 1c98f22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 6 additions & 1 deletion datashuttle/utils/ds_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions datashuttle/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def log(message: str) -> None:
"""
if ds_logger.logging_is_active():
logger = ds_logger.get_logger()
breakpoint()
logger.debug(message)


Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 1c98f22

Please sign in to comment.