
    .`i                     h    d dl Z d dlmZ d dlmZ  G d de j                  Z G d de          ZdS )    N)Path)envsc                   .     e Zd ZdZd fd	Z fdZ xZS )NewLineFormatterz=Adds logging prefix to newlines to align multi-line messages.N%c                     t                                          |||           t          j        dk    | _        | j        r<t          t                                                    j        j        j        | _	        d S d S )NDEBUG)
super__init__r   VLLM_LOGGING_LEVELuse_relpathr   __file__resolveparentroot_dirselffmtdatefmtstyle	__class__s       p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/logging_utils/formatter.pyr   zNewLineFormatter.__init__   sm    gu---2g= 	J NN2244;BIDMMM	J 	J    c                 J   dt           dt          fd}| j        rt          |dd           }|r_	 t          |                                                              | j                  }n8# t          $ r t          |j                  }Y nw xY wt          |j                  } ||          |_	        n|j        |_	        t                                          |          }|j        dk    r9|                    |j                  }|                    dd|d         z             }|S )	Nrelpathreturnc                 Z   t          | j                  }g }|r|d         dk    r
|dd         }|r$|d         dk    r||dd         z  }|dd         }n|r||dd         z  }|dd         }t          |          dk    r|dg|dd         z   z  }n||z  }d	                    |          S )
a`  
            Shortens a file path for logging display:
            - Removes leading 'vllm' folder if present.
            - If path starts with 'v1',
            keeps the first two and last two levels,
            collapsing the middle as '...'.
            - Otherwise, keeps the first and last two levels,
            collapsing the middle as '...'.
            - If the path is short, returns it as-is.
            - Examples:
            vllm/model_executor/layers/quantization/utils/fp8_utils.py ->
            model_executor/.../quantization/utils/fp8_utils.py
            vllm/model_executor/layers/quantization/awq.py ->
            model_executor/layers/quantization/awq.py

            Args:
                relpath (Path): The relative path to be shortened.
            Returns:
                str: The shortened path string for display.
            r   vllm   Nv1   z.../)listpartslenjoin)r   r%   	new_partss      r   shrink_pathz,NewLineFormatter.format.<locals>.shrink_path   s    * ''EI "qV++abb	 "qT))U2A2Y&	abb	 "U2A2Y&	abb	5zzA~~eWuRSSz11		U"	88I&&&r   pathname 
z
r   )r   strr   getattrr   relative_tor   	Exceptionfilenamefileinfor
   formatmessagesplitreplace)r   recordr)   abs_pathr   msgr%   r   s          r   r3   zNewLineFormatter.format   s+   #	' #	'# #	' #	' #	' #	'J  	.vz488H 04"8nn4466BB4=QQGG  4 4 4"6?33GGG4 v//)k'22FOO$oFOggnnV$$>RIIfn--E++dFU1X$566C
s   9A) )B
	B
Nr   )__name__
__module____qualname____doc__r   r3   __classcell__r   s   @r   r   r   
   sb        GGJ J J J J J7 7 7 7 7 7 7 7 7r   r   c                   F     e Zd ZdZddddddZdZd	Zd fd	Z fdZ xZ	S )ColoredFormattera  Adds ANSI color codes to log levels for terminal output.

    This formatter adds colors by injecting them into the format string for
    static elements (timestamp, filename, line number) and modifying the
    levelname attribute for dynamic color selection.
    z[37mz[32mz[33mz[31mz[35m)r	   INFOWARNINGERRORCRITICALz[90mz[0mNr   c                     |rJ|                     d| j         d| j                   }|                     d| j         d| j                   }t                                          |||           d S )Nz%(asctime)sz[%(fileinfo)s:%(lineno)d])r6   GREYRESETr
   r   r   s       r   r   zColoredFormatter.__init__a   s     	++m	-R-Rdj-R-RSSC+++9CCtzCC C 	gu-----r   c                     |j         }| j                            |j                   x}| |j          | j         |_         t	                                          |          }||_         |S )N)	levelnameCOLORSgetrI   r
   r3   )r   r7   orig_levelname
color_coder9   r   s        r   r3   zColoredFormatter.formato   sl    ) +//&*:;;;JH",Lf.>L
LLF ggnnV$$ *
r   r:   )
r;   r<   r=   r>   rL   rH   rI   r   r3   r?   r@   s   @r   rB   rB   N   s           F DE. . . . . .        r   rB   )loggingpathlibr   r   r   	Formatterr   rB    r   r   <module>rT      s                A A A A Aw( A A AH/ / / / /' / / / / /r   