Skip to content

Commit

Permalink
fix for recursion error if custom-logger is tomodachi.logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaspuff committed Aug 14, 2023
1 parent c62e2b3 commit 28f3f35
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tomodachi/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@ def set_custom_logger_factory(
logger_factory: Optional[Union[str, ModuleType, type, object]] = TOMODACHI_CUSTOM_LOGGER
) -> None:
if logger_factory is not None and logger_factory:
_CustomLogger.get_logger_factory(logger_factory)
logger_factory_ = _CustomLogger.get_logger_factory(logger_factory)
if logger_factory_ is sys.modules[__name__]:
# cannot set custom logger factory to tomodachi.logger itself
logger_factory = None
set_default_formatter("console")

Check warning on line 560 in tomodachi/logging.py

View check run for this annotation

Codecov / codecov/patch

tomodachi/logging.py#L559-L560

Added lines #L559 - L560 were not covered by tests

global TOMODACHI_CUSTOM_LOGGER
TOMODACHI_CUSTOM_LOGGER = logger_factory
Expand Down Expand Up @@ -661,7 +665,10 @@ def get_logger_factory(cls, custom_logger_factory: Optional[Union[str, ModuleTyp
if custom_logger_factory in cls._logger_factory_cache:
return cls._logger_factory_cache[custom_logger_factory]

Check warning on line 666 in tomodachi/logging.py

View check run for this annotation

Codecov / codecov/patch

tomodachi/logging.py#L666

Added line #L666 was not covered by tests

if "." in custom_logger_factory:
if custom_logger_factory in sys.modules:
module_name = custom_logger_factory
logger_factory = sys.modules[module_name]

Check warning on line 670 in tomodachi/logging.py

View check run for this annotation

Codecov / codecov/patch

tomodachi/logging.py#L669-L670

Added lines #L669 - L670 were not covered by tests
elif "." in custom_logger_factory:
module_name, module_attr = custom_logger_factory.rsplit(".", 1)
if module_name in sys.modules:
logger_factory = sys.modules[module_name].__dict__.get(module_attr)

Check warning on line 674 in tomodachi/logging.py

View check run for this annotation

Codecov / codecov/patch

tomodachi/logging.py#L672-L674

Added lines #L672 - L674 were not covered by tests
Expand Down

0 comments on commit 28f3f35

Please sign in to comment.