o
    㥵i	                     @   s>   d dl Z d dlmZmZ d dlmZmZ G dd de jZdS )    N)MappingOptional)rank_prefixed_messagerank_zero_onlyc                
       sh   e Zd ZdZe ddfdededeeeef  ddf fdd	Z		dd
e
dedee
 ddfddZ  ZS )RankedLoggerz0A multi-GPU-friendly python command line logger.TNnamer   extrareturnc                    s$   t |}t j||d || _dS )a  Initializes a multi-GPU-friendly python command line logger that logs on all processes
        with their rank prefixed in the log message.

        :param name: The name of the logger. Default is ``__name__``.
        :param rank_zero_only: Whether to force all logs to only occur on the rank zero process. Default is `False`.
        :param extra: (Optional) A dict-like object which provides contextual information. See `logging.LoggerAdapter`.
        )loggerr   N)logging	getLoggersuper__init__r   )selfr   r   r   r
   	__class__ L/home/ubuntu/.local/lib/python3.10/site-packages/fish_speech/utils/logger.pyr   
   s   

zRankedLogger.__init__levelmsgrankc                 O   s   |  |ra| ||\}}ttdd}|du rtdt||}| jr9|dkr7| jj||g|R i | dS dS |du rM| jj||g|R i | dS ||krc| jj||g|R i | dS dS dS )aD  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.

        :param level: The level to log at. Look at `logging.__init__.py` for more information.
        :param msg: The message to log.
        :param rank: The rank to log at.
        :param args: Additional args to pass to the underlying logging function.
        :param kwargs: Any additional keyword args to pass to the underlying logging function.
        r   Nz4The `rank_zero_only.rank` needs to be set before user   )isEnabledForprocessgetattrr   RuntimeErrorr   r
   log)r   r   r   r   argskwargscurrent_rankr   r   r   r      s$   

   zRankedLogger.log)N)__name__
__module____qualname____doc__strboolr   r   objectr   intr   __classcell__r   r   r   r   r      s0    r   )	r   typingr   r   "lightning_utilities.core.rank_zeror   r   LoggerAdapterr   r   r   r   r   <module>   s    