Returns True if this is the "first" call for a given key. Various logging settings can adjust the definition of "first". Args: key: A unique identifier for the call site. Returns: True if this is the first call for ``key`` (subject to the current ``log_once`` s
(key: str)
| 16 | |
| 17 | @DeveloperAPI |
| 18 | def log_once(key: str) -> bool: |
| 19 | """Returns True if this is the "first" call for a given key. |
| 20 | |
| 21 | Various logging settings can adjust the definition of "first". |
| 22 | |
| 23 | Args: |
| 24 | key: A unique identifier for the call site. |
| 25 | |
| 26 | Returns: |
| 27 | True if this is the first call for ``key`` (subject to the current |
| 28 | ``log_once`` settings), False otherwise. |
| 29 | |
| 30 | Example: |
| 31 | |
| 32 | .. testcode:: |
| 33 | |
| 34 | import logging |
| 35 | from ray.util.debug import log_once |
| 36 | |
| 37 | logger = logging.getLogger(__name__) |
| 38 | if log_once("some_key"): |
| 39 | logger.info("Some verbose logging statement") |
| 40 | """ |
| 41 | |
| 42 | global _last_logged |
| 43 | |
| 44 | if _disabled: |
| 45 | return False |
| 46 | elif key not in _logged: |
| 47 | _logged.add(key) |
| 48 | _last_logged = time.time() |
| 49 | return True |
| 50 | elif _periodic_log and time.time() - _last_logged > 60.0: |
| 51 | _logged.clear() |
| 52 | _last_logged = time.time() |
| 53 | return False |
| 54 | else: |
| 55 | return False |
| 56 | |
| 57 | |
| 58 | @DeveloperAPI |
no test coverage detected
searching dependent graphs…