U
    d                     @   sz   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ dee dddZ	dee dddZ
deee d
ddZdS )    N)Optional)get_log_levelnamec                 C   s   t | ptddS )ao  
    Util function to set up a simple logger that writes
    into stderr. The loglevel is fetched from the LOGLEVEL
    env. variable or WARNING as default. The function will use the
    module name of the caller if no name is provided.

    Args:
        name: Name of the logger. If no name provided, the name will
              be derived from the call stack.
       )depth)_setup_logger_derive_module_namer    r
   K/tmp/pip-unpacked-wheel-ua33x9lu/torch/distributed/elastic/utils/logging.py
get_logger   s    r   c                 C   s$   t | }|tjdt  |S )NZLOGLEVEL)logging	getLoggersetLevelosenvirongetr   )r   logr
   r
   r   r   #   s    
r      )r   returnc              
   C   s   z`t  }| t|k st||  }t |d }|r<|j}n |d }tjtj	|d }|W S  t
k
r } ztd| t W Y dS d}~X Y nX dS )z
    Derives the name of the caller module from the stack frames.

    Args:
        depth: The position of the frame in the stack.
    r   r   z<Error deriving logger module name, using <None>. Exception: N)inspectstacklenAssertionError	getmodule__name__r   pathsplitextbasename	ExceptionwarningswarnRuntimeWarning)r   r   Z
frame_infomodulemodule_namefilenameer
   r
   r   r	   )   s     r	   )N)N)r   )r   r   r   r    typingr   Z)torch.distributed.elastic.utils.log_levelr   strr   r   intr	   r
   r
   r
   r   <module>	   s   