o
    h                  	   @   s  d Z ddlZ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	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZ ddlmZ ejZejZejZejZejZe d
ZdZddeedidddeediddgdddidddZe	dedededdfddZ e	dedededdfddZ!e	dedededdfddZ"G d d! d!eZ#e e!e"d"Z$d.d#d$Z%d%ede#fd&d'Z&e%  e&e'Z(d/d(d)Z)	d/d*ed+ee fd,d-Z*dS )0zLogging configuration for vLLM.    N)Hashable)	lru_cachepartial)Logger)
dictConfig)path)
MethodType)AnyOptionalcastz?%(levelname)s %(asctime)s [%(fileinfo)s:%(lineno)d] %(message)sz%m-%d %H:%M:%SZvllm#vllm.logging_utils.NewLineFormatter)classdatefmtformatzlogging.StreamHandler)r   	formatterlevelstreamDEBUGF)handlersr   	propagate   )
formattersr   loggersversiondisable_existing_loggersloggermsgargsreturnc                 G      | j |g|R ddi d S N
stacklevel   )debugr   r   r    r%   6/usr/local/lib/python3.10/site-packages/vllm/logger.py_print_debug_once9      r'   c                 G   r   r    )infor$   r%   r%   r&   _print_info_once?   r(   r*   c                 G   r   r    )warningr$   r%   r%   r&   _print_warning_onceE   r(   r,   c                   @   sR   e Zd ZdZdededdfddZdededdfdd	Zdededdfd
dZdS )_VllmLoggera
  
    Note:
        This class is just to provide type information.
        We actually patch the methods directly on the [`logging.Logger`][]
        instance to avoid conflicting with other libraries such as
        `intel_extension_for_pytorch.utils._logger`.
    r   r   r   Nc                 G      t | |g|R   dS )z~
        As [`debug`][logging.Logger.debug], but subsequent calls with
        the same message are silently dropped.
        N)r'   selfr   r   r%   r%   r&   
debug_onceT      z_VllmLogger.debug_oncec                 G   r.   )z|
        As [`info`][logging.Logger.info], but subsequent calls with
        the same message are silently dropped.
        N)r*   r/   r%   r%   r&   	info_once[   r2   z_VllmLogger.info_oncec                 G   r.   )z
        As [`warning`][logging.Logger.warning], but subsequent calls with
        the same message are silently dropped.
        N)r,   r/   r%   r%   r&   warning_onceb   r2   z_VllmLogger.warning_once)	__name__
__module____qualname____doc__strr   r1   r3   r4   r%   r%   r%   r&   r-   K   s
    r-   )r1   r3   r4   c                  C   s   t ttf  } tstrtdtrt} trKttstdtt	tdd}t
| }W d    n1 s7w   Y  t|t sItdt|j|} | di  D ]}|ddkr`d	|d< qS| rit|  d S d S )
NzVLLM_CONFIGURE_LOGGING evaluated to false, but VLLM_LOGGING_CONFIG_PATH was given. VLLM_LOGGING_CONFIG_PATH implies VLLM_CONFIGURE_LOGGING. Please enable VLLM_CONFIGURE_LOGGING or unset VLLM_LOGGING_CONFIG_PATH.z6Could not load logging config. File does not exist: %szutf-8)encodingz.Invalid logging config. Expected dict, got %s.r   r   zvllm.logging.NewLineFormatterr   )dictr9   r	   VLLM_CONFIGURE_LOGGINGVLLM_LOGGING_CONFIG_PATHRuntimeErrorDEFAULT_LOGGING_CONFIGr   existsopenjsonloadsread
isinstance
ValueErrortyper5   getvaluesr   )Zlogging_configfileZcustom_configr   r%   r%   r&   _configure_vllm_root_loggerr   s8   

rK   namec                 C   s8   t | }t D ]\}}t||t|| q	tt|S )zThe main purpose of this function is to ensure that loggers are
    retrieved in such a way that we can be sure the root vllm logger has
    already been configured.)logging	getLogger_METHODS_TO_PATCHitemssetattrr   r   r-   )rL   r   method_namemethodr%   r%   r&   init_logger   s   

rT   c                 C   s.  |dv r|j j}|j}|j j}||sd S zq|j}|d ur*|j j}	|j}
|j j}nd}	d}
d}t| dI}tj 	d}|dkr]|
| d| d| d	| d
| d|	 d	|
 d n|
| d| d| d	| d| d|	 d	|
 d W d    n1 sw   Y  W n	 ty   Y nw tt| |S )N)callr    r   az%Y-%m-%d %H:%M:%S.%frU   z	 Call to z in :z from 
z Return from z to )f_codeco_filenamef_linenoco_name
startswithf_backrA   datetimenowstrftimewrite	NameErrorr   _trace_calls)log_pathroot_dirframeeventargfilenamelineno	func_nameZ
last_frameZlast_filenameZlast_linenoZlast_func_nameftsr%   r%   r&   re      sf   




re   log_file_pathrg   c                 C   sH   t d t d|  |du rtjtjt}tt	t
| | dS )a  
    Enable tracing of every function call in code under `root_dir`.
    This is useful for debugging hangs or crashes.
    `log_file_path` is the path to the log file.
    `root_dir` is the root directory of the code to trace. If None, it is the
    vllm root directory.

    Note that this call is thread-level, any threads calling this function
    will have the trace enabled. Other threads will not be affected.
    zVLLM_TRACE_FUNCTION is enabled. It will record every function executed by Python. This will slow down the code. It is suggested to be used for debugging hang or crashes only.zTrace frame log is saved to %sN)r   r+   r)   osr   dirname__file__syssettracer   re   )rp   rg   r%   r%   r&   enable_trace_function_call   s   rv   )r   N)N)+r8   r`   rB   rM   rq   rt   collections.abcr   	functoolsr   r   r   logging.configr   r   typesr   typingr	   r
   r   Z	vllm.envsZenvsr<   r=   ZVLLM_LOGGING_LEVELZVLLM_LOGGING_PREFIXZVLLM_LOGGING_STREAMZ_FORMATZ_DATE_FORMATr?   r9   r'   r*   r,   r-   rO   rK   rT   r5   r   re   rv   r%   r%   r%   r&   <module>   s~   
	!
#
(