easydel.utils.helpers#
- class easydel.utils.helpers.ColorFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#
Bases:
Formatter- format(record: LogRecord) str[source]#
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class easydel.utils.helpers.DummyStream[source]#
Bases:
objectA null device-like stream that discards all writes.
- class easydel.utils.helpers.LazyLogger(name: str, level: Optional[int] = None)[source]#
Bases:
object
- easydel.utils.helpers.capture_time()[source]#
A context manager that measures elapsed time.
- Returns
Callable that returns the current elapsed time while the context is active, or the final elapsed time after the context exits.
Example
- with capture_time() as get_time:
# Do some work print(f”Current time: {get_time()}”)
print(f”Final time: {get_time()}”)
- easydel.utils.helpers.get_logger(name: str, level: Optional[int] = None) LazyLogger[source]#
Function to create a lazy logger that only initializes when first used.
- Parameters
name (str) – The name of the logger.
level (Optional[int]) – The logging level. Defaults to environment variable LOGGING_LEVEL_ED or “INFO”.
- Returns
A lazy logger instance that initializes on first use.
- Return type
- easydel.utils.helpers.quiet(suppress_stdout=True, suppress_stderr=True)[source]#
Context manager to temporarily suppress stdout and/or stderr output. :param suppress_stdout: Whether to suppress stdout :type suppress_stdout: bool :param suppress_stderr: Whether to suppress stderr :type suppress_stderr: bool
- Usage:
- with suppress_output():
# Code that generates unwanted output print(“This won’t be displayed”)
Note
This will suppress ALL output to the specified streams within the context, including output from C extensions and system calls.