Skip to content

Commit

Permalink
fix bad definitions of under_info and debug_enable
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekisr committed Feb 8, 2022
1 parent 221e6c9 commit 41b674a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/common/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def _make_decorator(
) -> Decorated:
def decorator(decorated: Decorated):
decorated_logger = _get_logger(decorated)
is_debug_enable = decorated_logger.isEnabledFor(logging.DEBUG)
is_under_info = decorated_logger.level < logging.INFO

def decorator_class(clazz: Type[Any]) -> Type[Any]:
_decorate_class_members_with_logs(clazz)
Expand All @@ -106,6 +104,8 @@ def decorator_func(func: Function, prefix_name: str = "") -> Function:
has_return_value = func_signature.return_annotation not in empty_and_none
is_private = func_name.startswith(_PRIVATE_PREFIX_SYMBOL)
full_func_name = f"{prefix_name}.{func_name}"
under_info = None
debug_enable = None

@wraps(func)
def _wrapper_func(*args, **kwargs) -> Any:
Expand All @@ -119,11 +119,24 @@ def _log_enter_to_function(*args, **kwargs) -> None:
decorated_logger.info(
f"{prefix_enter_msg}'{full_func_name}'{suffix_enter_msg}"
)
elif is_debug_enable:
elif _is_debug_enable():
_log_debug(*args, **kwargs)

def _is_log_info() -> bool:
return not (is_under_info or is_private or is_fixture)
return not (_is_under_info() or is_private or is_fixture)

def _is_under_info() -> bool:
nonlocal under_info
if under_info is None:
under_info = decorated_logger.getEffectiveLevel() < logging.INFO
return under_info

def _is_debug_enable() -> bool:
nonlocal debug_enable
if debug_enable is None:
debug_enable = decorated_logger.isEnabledFor(logging.DEBUG)
return debug_enable


def _log_debug(*args, **kwargs) -> None:
used_parameters = getcallargs(func, *args, **kwargs)
Expand All @@ -140,7 +153,7 @@ def _log_debug(*args, **kwargs) -> None:
)

def _log_exit_of_function(return_value: Any) -> None:
if is_debug_enable and has_return_value:
if _is_debug_enable() and has_return_value:
decorated_logger.debug(
f"{prefix_out_msg}'{full_func_name}'{return_value_msg_part}"
f"'{return_value}'{suffix_out_msg}"
Expand Down

0 comments on commit 41b674a

Please sign in to comment.