Logging#
loggers
#
get_logger
#
Retrieve a logger with the specified log level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Name of Logger Instance |
required |
|
str
|
Desired logging level. |
'INFO'
|
Returns:
| Type | Description |
|---|---|
logging.Logger
|
Configured logger instance. |
Source code in src/imgnet/loggers/__init__.py
temporary_log_level
#
temporary_log_level(logger: structlog.stdlib.BoundLogger, level: str) -> typing.Generator[None, typing.Any, None]
Temporarily change the log level of a logger within a context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
structlog.stdlib.BoundLogger
|
The logger instance to modify |
required |
|
str
|
The temporary log level to set |
required |
Examples:
>>> with temporary_log_level(logger, "ERROR"):
... # Only ERROR and CRITICAL messages will be logged in this block
... logger.warning("This won't be logged")
... logger.error("This will be logged")
Source code in src/imgnet/loggers/__init__.py
tqdm_logging_redirect
#
tqdm_logging_redirect(logger_name: str = 'imgnet') -> contextlib.AbstractContextManager[None]
Context manager to redirect logging output into tqdm for cleaner logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the logger to redirect, by default "imgnet". |
'imgnet'
|
Examples:
>>> from tqdm import tqdm
>>> import time
>>> with tqdm_logging_redirect():
... for i in tqdm(range(10), desc="Processing"):
... logger.info(f"Processing {i}")
... time.sleep(0.1)