o
    }o™iÈ	  ã                   @   s<   d dl Zd dlmZ d dlmZ i ZdZdd„ Z	dd„ Z
dS )é    N)ÚMemoryHandlerFc                   C   sV   t s)tdƒt d< t d  dd„ ¡ tdƒt d< tj t d ¡ tj t d ¡ dS dS )a  
    Adds two MemoryHandlers to pytorch_lightning's logger. These two handlers are essentially message buffers. This
    function is called in nemo.utils.__init__.py. These handlers are used in add_filehandlers_to_pl_logger to flush
    buffered messages to files.
    éÿÿÿÿÚ
memory_errc                 S   ó   | j tjkS ©N©ÚlevelnoÚ_loggingÚINFO©Úrecord© r   úU/home/ubuntu/.local/lib/python3.10/site-packages/nemo/utils/lightning_logger_patch.pyÚ<lambda>    ó    z2add_memory_handlers_to_pl_logger.<locals>.<lambda>Ú
memory_allN)ÚHANDLERSr   Ú	addFilterÚplÚ_loggerÚ
addHandlerr   r   r   r   Ú add_memory_handlers_to_pl_logger   s   ûr   c                 C   s¶   t  | ¡td< tj td ¡ t  |¡td< td  dd„ ¡ tj td ¡ t dd¡r?td  td ¡ td  	¡  td= t dd¡rYtd  td ¡ td  	¡  td= dS dS )aŒ  
    Adds two filehandlers to pytorch_lightning's logger. Called in nemo.utils.exp_manager(). The first filehandler
    logs all messages to all_log_file while the second filehandler logs all WARNING and higher messages to err_log_file.
    If "memory_err" and "memory_all" exist in HANDLERS, then those buffers are flushed to err_log_file and all_log_file
    respectively, and then closed.
    ÚfileÚfile_errc                 S   r   r   r   r   r   r   r   r   0   r   z/add_filehandlers_to_pl_logger.<locals>.<lambda>r   Nr   )
r	   ÚFileHandlerr   r   r   r   r   ÚgetÚ	setTargetÚclose)Úall_log_fileÚerr_log_filer   r   r   Úadd_filehandlers_to_pl_logger&   s   
ýr    )Úloggingr	   Úlogging.handlersr   Úlightning.pytorchÚpytorchr   r   ÚPATCHEDr   r    r   r   r   r   Ú<module>   s   