-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46f9767
commit a05433c
Showing
2 changed files
with
4 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters