Skip to content

Commit

Permalink
simplify and address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavgarg1 committed Nov 29, 2022
1 parent 46f9767 commit a05433c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
23 changes: 3 additions & 20 deletions ludwig/utils/logging_utils.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
import time

_logged = set()
_disabled = False
_periodic_log = False
_last_logged = 0.0


def log_once(key):
def log_once(key: str) -> bool:
"""Returns True if this is the "first" call for a given key.
Various logging settings can adjust the definition of "first".
Example:
if log_once("some_key"):
logger.info("Some verbose logging statement") # noqa
"""

global _last_logged

if _disabled:
return False
elif key not in _logged:
if key not in _logged:
_logged.add(key)
_last_logged = time.time()
return True
elif _periodic_log and time.time() - _last_logged > 60.0:
_logged.clear()
_last_logged = time.time()
return False
else:
return False
return False
2 changes: 1 addition & 1 deletion ludwig/utils/structural_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ludwig.utils.logging_utils import log_once


def warn_structure_refactor(old_module: str, new_module: str, direct: bool = True):
def warn_structure_refactor(old_module: str, new_module: str, direct: bool = True) -> None:
"""Create structure refactor warning to indicate modules new location post.
Only creates a warning once per module.
Expand Down

0 comments on commit a05433c

Please sign in to comment.