pylogger
RankedLogger
A multi-GPU-friendly logger based on loguru that adds rank information to messages.
Examples:
caplog = getfixture(‘caplog’) from lightning_utilities.core.rank_zero import rank_zero_only
Set up the rank for testing
rank_zero_only.rank = 0
Create logger instance
log = RankedLogger(rank_zero_only=False)
Test logging
log.info(“This is an info message”) assert “[rank0] This is an info message” in caplog.text
log.debug(“This is a debug message”, rank=0) assert “[rank0] This is a debug message” in caplog.text
Test rank zero only mode
log_zero = RankedLogger(rank_zero_only=True) log_zero.info(“This only logs on rank 0”) assert “[rank0] This only logs on rank 0” in caplog.text
Source code in meds_torch/utils/pylogger.py
__init__(name='ranked_logger', rank_zero_only=False)
Initialize the ranked logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
Name identifier for the logger |
'ranked_logger'
|
rank_zero_only |
bool
|
Whether to force all logs to only occur on rank zero process |
False
|