
    -`i&+              	       \   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m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 ddlmZmZ ej         dZdZde fdZ!deeddeedddd e!            rdndej"        ej#        diddgej"        ddidddZ$edede%deddfd            Z&edede%deddfd             Z'edede%deddfd!            Z(ed"         Z)d#e)de fd$Z* G d% d&e          Z+e+j,        e+j-        e+j.        d'Z/d6d(Z0d)e%de+fd*Z1e
ej2        fd+e3dededf         fd,            Z4d-eded.         fd/Z5 e0             ej"        d0k    r( ej6        d1          7                    ej8                    e1e9          Z:d7d2Z;d7d3e%d4e%dz  fd5Z<dS )8zLogging configuration for vLLM.    N)	GeneratorHashable)contextmanager)	lru_cachepartial)Logger)
dictConfig)path)
MethodType)AnyLiteralcast)ColoredFormatterNewLineFormatterz?%(levelname)s %(asctime)s [%(fileinfo)s:%(lineno)d] %(message)sz%m-%d %H:%M:%Sreturnc                     t           j        st           j        dk    rdS t           j        dk    rdS t           j        dk    r8t	          t
          j        d          ot
          j                                        S t           j        dk    r8t	          t
          j        d          ot
          j                                        S dS )N0F1Tzext://sys.stdoutisattyzext://sys.stderr)	envsNO_COLORVLLM_LOGGING_COLORVLLM_LOGGING_STREAMhasattrsysstdoutr   stderr     _/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/logger.py
_use_colorr!      s    } /366u#%%t#555sz8,,D1B1B1D1DD		!%7	7	7sz8,,D1B1B1D1DD5r   #vllm.logging_utils.NewLineFormatter)classdatefmtformatz#vllm.logging_utils.ColoredFormatter)vllm
vllm_colorr&   zlogging.StreamHandlerr'   )r#   	formatterlevelstreamF)handlersr)   	propagate   )
formattersr+   loggersversiondisable_existing_loggersloggermsgargsc                 (     | j         |g|R ddi d S N
stacklevel   )debugr2   r3   r4   s      r    _print_debug_oncer;   K   s,     FL*t********r   c                 (     | j         |g|R ddi d S r6   )infor:   s      r    _print_info_oncer>   Q   s,     FK)d)))q)))))r   c                 (     | j         |g|R ddi d S r6   )warningr:   s      r    _print_warning_oncerA   W   s,     FN3,,,,!,,,,,r   )processgloballocalscopec                 ^    | dk    rddl m}  |            S | dk    rddl m}  |            S dS )z$Decide whether to log based on scoperC   r   )is_global_first_rankrD   )is_local_first_rankT)vllm.distributed.parallel_staterG   rH   )rE   rG   rH   s      r    _should_log_with_scoperJ   `   s_    HHHHHH##%%%GGGGGG""$$$4r   c            	       l    e Zd ZdZdddedededdfd	Zdddedededdfd
Zdddedededdf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`.
    rB   )rE   r3   r4   rE   r   Nc                D    t          |          sdS t          | |g|R   dS )z~
        As [`debug`][logging.Logger.debug], but subsequent calls with
        the same message are silently dropped.
        N)rJ   r;   selfr3   rE   r4   s       r    
debug_oncez_VllmLogger.debug_oncew   s7     &e,, 	F$+d++++++r   c                D    t          |          sdS t          | |g|R   dS )z|
        As [`info`][logging.Logger.info], but subsequent calls with
        the same message are silently dropped.
        N)rJ   r>   rN   s       r    	info_oncez_VllmLogger.info_once   s7    
 &e,, 	Fs*T******r   c                D    t          |          sdS t          | |g|R   dS )z
        As [`warning`][logging.Logger.warning], but subsequent calls with
        the same message are silently dropped.
        N)rJ   rA   rN   s       r    warning_oncez_VllmLogger.warning_once   s7     &e,, 	FD#-------r   )
__name__
__module____qualname____doc__strr   LogScoperP   rR   rT   r   r   r    rL   rL   n   s          <E	, 	, 	,	,'	,08	,		, 	, 	, 	, FO + + +S + +( +SW + + + + <E	. 	. 	.	.'	.08	.		. 	. 	. 	. 	. 	.r   rL   )rP   rR   rT   c                     t          t          t          f                     } t          j        st          j        rt          d          t          j        ret          } | d         d         }t          j        |d<   t          j	        |d<   t                      rdnd|d<   | d         d         }t          j        |d<   t          j        rt          j        t          j                  st          d	t          j                  t          t          j        d
          5 }t          j        |                                          }d d d            n# 1 swxY w Y   t#          |t                     s"t%          dt'          |          j                  |} |                     di                                           D ] }|                    d          dk    rd|d<   !| rt/          |            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.r+   r&   r)   r*   r'   r(   r/   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"   )dictrY   r   r   VLLM_CONFIGURE_LOGGINGVLLM_LOGGING_CONFIG_PATHRuntimeErrorDEFAULT_LOGGING_CONFIGVLLM_LOGGING_LEVELr   r!   r
   existsopenjsonloadsread
isinstance
ValueErrortyperU   getvaluesr	   )logging_configvllm_handlervllm_loggersfilecustom_configr(   s         r    _configure_vllm_root_loggerrr      s    #s(^%%N& 
4+H 
H
 
 	
 " 
8/%j1&9 $ 7W!%!9X4>LL$LLLf[!%i08 $ 7W$ '{4899 	H-   $/'BBB 	4d Jtyy{{33M	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 -.. 	@]##,   '#''b99@@BB G G	==!!%DDD!FIg #>"""""# #s   'EEEnamec           	          t          j        |           }t                                          D ]$\  }}t	          ||t          ||                     %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   rL   )rs   r2   method_namemethods       r    init_loggerr|      se    
 t$$F06688 A AVZ%?%?@@@@V$$$r   r)   c              #      K   t           j        j        j        }t          j        |            d V  t          j        |           d S N)ru   rootmanagerdisable)r)   current_levels     r    suppress_loggingr      sB      L(0MOE	EEEOM"""""r   lgr)colornewlineNc                    | ~| j         rnt          | j                   dk    rV| j         d         j        dk    r@| j         d         j        }t	          |t
                    rdS t	          |t                    rdS | j        } | ~d S )Nr-   r   r&   r   r   )r+   lenrs   r(   rh   r   r   parent)r   r(   s     r    current_formatter_typer      s    
/< 	!C--22s|A7Kv7U7UQ1I)%566 w)%566 ! yj / 4r   INFOhttpxc                    |dv r+|j         j        }|j        }|j         j        }|                    |          sd S 	 |j        }| |j         j        }	|j        }
|j         j        }nd}	d}
d}t          | d          5 }t          j                                        	                    d          }|dk    r+|
                    | d| d| d	| d
| d|	 d	|
 d           n*|
                    | d| d| d	| d| d|	 d	|
 d           d d d            n# 1 swxY w Y   n# t          $ r Y nw xY wt          t          | |          S )N)callr    r   az%Y-%m-%d %H:%M:%S.%fr   z	 Call to z in :z from 
z Return from z to )f_codeco_filenamef_linenoco_name
startswithf_backrd   datetimenowstrftimewrite	NameErrorr   _trace_calls)log_pathroot_dirframeeventargfilenamelineno	func_name
last_framelast_filenamelast_linenolast_func_nameftss                 r    r   r      sC   """<+L(	""8,, 	F	J% * 1 =(1!+!2!: !#!#h$$ &**,,556LMMF??GG + +%+ ++3+ +6<+ +!/+ +5B+ + '+ + +    GG + +%+ ++3+ +6<+ +-+ +3@+ + '+ + +                   	 	 	D	 <8444s6   ?D! <BD	D! DD! DD! !
D.-D.log_file_pathr   c                 F   t                               d           t                               d|            |At          j                            t          j                            t                              }t          j        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)r2   r@   r=   osr
   dirname__file__r   settracer   r   )r   r   s     r    enable_trace_function_callr   (  s     NN	F  
 KK0-@@@7??27??8#<#<==L}h??@@@@@r   )r   Nr~   )=rX   r   re   ru   r   r   collections.abcr   r   
contextlibr   	functoolsr   r   r   logging.configr	   r
   typesr   typingr   r   r   	vllm.envsr   vllm.logging_utilsr   r   VLLM_LOGGING_PREFIX_FORMAT_DATE_FORMATboolr!   rb   r   ra   rY   r;   r>   rA   rZ   rJ   rL   rP   rR   rT   rw   rr   r|   r   intr   r   rv   setLevelWARNINGrU   r2   r   r   r   r   r    <module>r      sb   & %    				 



 / / / / / / / / % % % % % % ( ( ( ( ( ( ( (       % % % % % %             % % % % % % % % % %       A A A A A A A A  , , ,   	D 	 	 	 	 ;#
 
 ;#
 
  	,)3A6,.
 
 	,
 
  %=  D +f +3 +x +D + + + +
 *V *# *h *4 * * * *
 - -S - -d - - - -
 /0( t    &. &. &. &. &.& &. &. &.V (&,  -# -# -# -#`
%c 
%k 
% 
% 
% 
% "), # #C #9T3_3M # # # #	 	73K+L 	 	 	 	      f$$Gg''888	X		(5 (5 (5 (5VA Ac AS4Z A A A A A Ar   