pylogger

class RankedLogger(name: str = 'mldft.utils.log_utils.pylogger', rank_zero_only: bool = False, extra: Mapping[str, object] | None = None)[source]

A multi-GPU-friendly python command line logger.

__init__(name: str = 'mldft.utils.log_utils.pylogger', rank_zero_only: bool = False, extra: Mapping[str, object] | None = None) None[source]

Initializes a multi-GPU-friendly python command line logger that logs on all processes with their rank prefixed in the log message.

Parameters:
  • name – The name of the logger. Default is __name__.

  • rank_zero_only – Whether to force all logs to only occur on the rank zero process. Default is False.

  • extra – (Optional) A dict-like object which provides contextual information. See logging.LoggerAdapter.

log(level: int, msg: str, rank: int | None = None, *args, **kwargs) None[source]

Delegate a log call to the underlying logger, after prefixing its message with the rank of the process it’s being logged from. If ‘rank’ is provided, then the log will only occur on that rank/process.

Parameters:
  • level – The level to log at. Look at logging.__init__.py for more information.

  • msg – The message to log.

  • rank – The rank to log at.

  • args – Additional args to pass to the underlying logging function.

  • kwargs – Any additional keyword args to pass to the underlying logging function.