scalarstop._logging
¶
Secret logging utilities that will help out.
Module Contents¶
Classes¶
Context manager that prints out how long the containing code took to execute. |
- class Timeblock(*, name: str, print_function: Optional[Callable] = None, print_start: bool = True)¶
Context manager that prints out how long the containing code took to execute.
- Usage:
import time with Timeblock(name=”helloworld”):
time.sleep(5) print(“Hello world”)
- If you want to send a custom logging function, do as follows:
import logging import time with Timeblock(name=”helloworld”, print_function=logging.debug):
time.sleep(5) print(“Hello world”)
- Parameters
name – The name of this timer. We print it at the beginning of every logging message.
print_function – A Python callable that can accept a single string logging argument.
print_start – Set this ``False` to suppress the logging message at the start of the timing process.