o
    `۷i                     @   s   d dl Z d dlZd dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZ deeef ded	efd
dZG dd dejeZG dd deZG dd deZdS )    N)ABCabstractmethod)AnyDictList)INTERNAL_TIMESTAMP_LOG_KEY)LOGGER_FORMAT)LOGGER_FLATTEN_KEYSLOGRECORD_STANDARD_ATTRSLogKeyformatted_attrskeyvaluec                 C   sj   |t v r/t|tstd| dt| | D ]\}}|| v r(td| || |< qdS || |< dS )a  Flatten the dictionary values for special keys and append the values in place.

    If the key is in `LOGGER_FLATTEN_KEYS`, the value will be flattened and appended
    to the `formatted_attrs` dictionary. Otherwise, the key-value pair will be appended
    directly.
    z#Expected a dictionary passing into z
, but got z(Found duplicated key in the log record: N)r	   
isinstancedict
ValueErrortypeitemsKeyError)r   r   r   kv r   L/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/_common/formatters.py_append_flatten_attributes   s   

r   c                       sx   e Zd Zdd fddZdee ddfdd	Zedee fd
dZde	j
defddZede	j
defddZ  ZS )AbstractFormatterN%Treturnc                    s   t  |||| g | _d S N)super__init___additional_log_standard_attrsselffmtdatefmtstylevalidate	__class__r   r   r   $   s   
zAbstractFormatter.__init__additional_log_standard_attrsc                 C   s
   || _ d S r   r    )r"   r)   r   r   r   !set_additional_log_standard_attrs(   s   
z3AbstractFormatter.set_additional_log_standard_attrsc                 C   s   | j S r   r*   )r"   r   r   r   r)   -   s   z/AbstractFormatter.additional_log_standard_attrsrecordc                 C   s   i }|s>| tjj| |tjj|jtjj| tj	j|j
tjj|jtjj|ji |jr>|js7| |j|_|j|tjj< | jD ]}t||t||d  qA|j D ]\}}|tvrat||| qSt|v ro|t|tjj< |S r   )updater   ASCTIMEr   
formatTime	LEVELNAME	levelnameMESSAGE
getMessageFILENAMEfilenameLINENOlinenoPROCESSprocessexc_infoexc_textformatExceptionEXC_TEXTr    r   getattr__dict__r   r
   r   popTIMESTAMP_NS)r"   r,   exclude_default_standard_attrsrecord_format_attrsr   r   r   r   r   generate_record_format_attrs1   s8   





z.AbstractFormatter.generate_record_format_attrsc                 C   s   d S r   r   )r"   r,   r   r   r   format]   s   zAbstractFormatter.formatNNr   Tr   N)__name__
__module____qualname__r   r   strr+   propertyr)   logging	LogRecordr   rD   r   rE   __classcell__r   r   r'   r   r   #   s     

,r   c                   @   s    e Zd ZdejdefddZdS )JSONFormatterr,   r   c                 C   s   | j |dd}t|S )NFrB   )rD   jsondumps)r"   r,   rC   r   r   r   rE   c   s   
zJSONFormatter.formatN)rH   rI   rJ   rM   rN   rK   rE   r   r   r   r   rP   b   s    rP   c                       s4   e Zd Zd
d fddZdejdefdd	Z  ZS )TextFormatterNr   Tr   c                    s"   t  |||| tt| _d S r   )r   r   rM   	Formatterr   _inner_formatterr!   r'   r   r   r   k   s   zTextFormatter.__init__r,   c                 C   s@   | j |}| j|dd}ddd | D }| d| S )NTrQ    c                 S   s   g | ]\}}| d | qS )=r   ).0r   r   r   r   r   
<listcomp>v   s    z(TextFormatter.format.<locals>.<listcomp>)rV   rE   rD   joinr   )r"   r,   srC   additional_attrsr   r   r   rE   o   s   zTextFormatter.formatrF   rG   )	rH   rI   rJ   r   rM   rN   rK   rE   rO   r   r   r'   r   rT   j   s    rT   )rR   rM   abcr   r   typingr   r   r   ray._private.logr   ray._private.ray_constantsr   "ray._private.ray_logging.constantsr	   r
   r   rK   r   rU   r   rP   rT   r   r   r   r   <module>   s    ?