
    Mi2                         S SK JrJr  S SKJr  S SKJrJrJrJ	r	  S SK
r
S SKJr  S SKJr  S SKJr  S SKJr  S	S
KJr   " S S\5      r " S S\\5      r " S S\5      r " S S\5      r " S S\5      rg)    )ABCabstractmethod)Enum)OptionalDictAnyListN)datetime)unquote)Console)Text   )create_box_messagec                   F    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrS rSrg)LogLevel   r   r                        	   
   c                 6    U R                   R                  5       $ N)namelowerselfs    o/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/crawl4ai/async_logger.py__str__LogLevel.__str__   s    yy       N)__name__
__module____qualname____firstlineno__DEFAULTDEBUGINFOSUCCESSWARNINGERRORCRITICALALERTNOTICE	EXCEPTIONFATALr#   __static_attributes__r&   r%   r"   r   r      s>    GEDGGEHEFIE!r%   r   c                   J    \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrS	rSrS
 rSrg)LogColor   zEnum for log colors.bright_blackcyangreenyellowredmagentazdim magentac                     U R                   $ )z+Automatically convert rich color to string.)valuer    s    r"   r#   LogColor.__str__,   s    zzr%   r&   N)r'   r(   r)   r*   __doc__r,   r-   r.   r/   r0   CYANGREENYELLOWMAGENTADIM_MAGENTAREDr#   r6   r&   r%   r"   r8   r8      sA    EDGGEDEFGK
Cr%   r8   c                      \ rS rSr\SS\S\4S jj5       r\SS\S\4S jj5       r\SS\S\4S jj5       r\SS\S\4S jj5       r	\SS\S\4S jj5       r
\SS	\S
\S\S\S\4
S jj5       r\SS	\S\S\S\4S jj5       rSrg)AsyncLoggerBase1   messagetagc                     g r   r&   r!   rM   rN   kwargss       r"   debugAsyncLoggerBase.debug2       r%   c                     g r   r&   rP   s       r"   infoAsyncLoggerBase.info6   rT   r%   c                     g r   r&   rP   s       r"   successAsyncLoggerBase.success:   rT   r%   c                     g r   r&   rP   s       r"   warningAsyncLoggerBase.warning>   rT   r%   c                     g r   r&   rP   s       r"   errorAsyncLoggerBase.errorB   rT   r%   urlrY   timing
url_lengthc                     g r   r&   )r!   ra   rY   rb   rN   rc   s         r"   
url_statusAsyncLoggerBase.url_statusF   rT   r%   r_   c                     g r   r&   )r!   ra   r_   rN   rc   s        r"   error_statusAsyncLoggerBase.error_statusJ   rT   r%   r&   Nr,   r-   r.   r/   r0   FETCHd   r0   rq   )r'   r(   r)   r*   r   strrR   rV   rY   r\   r_   boolfloatintre   rh   r6   r&   r%   r"   rK   rK   1   s   S s   C c   s    s    S s   c D % c ad    C c QT  r%   rK   c                      \ rS rSrSr0 SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_r\R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  0rS$\R                  S%S$S$S&4S'\\   S(\S)\S*\\\\4      S+\\\\4      S,\4S- jjrS.\S/\4S0 jrS.\S/\4S1 jrSLS2 jrS3\4S4 jr    SMS5\S3\S.\S6\\\\4      S+\\\\4      S7\\\      S8\\   4S9 jjrSNS3\S.\4S: jjrSOS3\S.\4S; jjrSPS3\S.\4S< jjrSQS3\S.\4S= jjrSRS3\S.\4S> jjrSSS3\S.\4S? jjr STS3\S.\4S@ jjr!SUS3\S.\4SA jjr"SVS3\S.\4SB jjr#SWS3\S.\4SC jjr$  SXSD\SE\SF\%S.\SG\4
SH jjr& SYSD\SI\S.\SG\4SJ jjr'SKr(g$)ZAsyncLoggerO   z
Asynchronous logger with support for colored console output and file logging.
Supports templated messages with colored components.
INITu   →READY   ✓rp   u   ↓SCRAPEu   ◆EXTRACTu   ■COMPLETEu   ●r0      ×r,   u   ⋯r-   u   ℹr/   u   ⚠r.   u   ✔r1   u   ‼r2   u   ⚡r3   r4   u   ❗r5   u   ☠r+   u   •Nr   Tlog_file	log_level	tag_widthiconscolorsverbosec                 h   Xl         X l        X0l        U=(       d    U R                  U l        U=(       d    U R
                  U l        X`l        [        5       U l	        U(       aP  [        R                  " [        R                  R                  [        R                  R                  U5      5      SS9  gg)a(  
Initialize the logger.

Args:
    log_file: Optional file path for logging
    log_level: Minimum log level to display
    tag_width: Width for tag formatting
    icons: Custom icons for different tags
    colors: Custom colors for different log levels
    verbose: Whether to output to console
Texist_okN)r   r   r   DEFAULT_ICONSr   DEFAULT_COLORSr   r   r   consoleosmakedirspathdirnameabspath)r!   r   r   r   r   r   r   s          r"   __init__AsyncLogger.__init__q   sw    ( !""0d00
3 3 3y KK(ABTR r%   rN   returnc                 B    SU S3R                  U R                  S5      $ )z#Format a tag with consistent width.[].)ljustr   r!   rN   s     r"   _format_tagAsyncLogger._format_tag   s!    3%qz44r%   c                 R    U R                   R                  XR                   S   5      $ )z=Get the icon for a tag, defaulting to info icon if not found.r-   )r   getr   s     r"   	_get_iconAsyncLogger._get_icon   s    zz~~c::f#566r%   c                     [        U5      U::  a  UR                  U5      $ U[        U5      -
  S-  nUSU U-   X* S -   nUR                  U5      $ )zETruncate text in the middle if longer than length, or pad if shorter.r   N)lenr   )r!   textlengthplaceholderhalf	shorteneds         r"   _shortenAsyncLogger._shorten   s[    t9::f%%[))a/$K+-UV<	v&&r%   rM   c                 H   U R                   (       a  [        R                  " U5      nUR                  n[        R
                  " 5       R                  S5      SS n[        U R                   SSS9 nUR                  SU SU S	35        SSS5        gg! , (       d  f       g= f)
z.Write a message to the log file if configured.%Y-%m-%d %H:%M:%S.%fNautf-8encodingr   ] 
)	r   r   from_markupplainr
   nowstrftimeopenwrite)r!   rM   r   
plain_text	timestampfs         r"   _write_to_fileAsyncLogger._write_to_file   s    ==##G,DJ //0FGLIdmmS7;q!I;bB78 <;	  <;s   0B
B!levelparamsboxes
base_colorc                 N   UR                   U R                  R                   :  a  gUR                  SS5      R                  SS5      n	U(       a  U	R                  " S0 UD6n
UR	                  5        H  u  p[        U5      R                  SS5      R                  SS5      nU(       a(  X;   a#  SX[    SU SX[    S3nU
R                  X5      n
UnU(       d  Mh  X;   d  Mo  U
R                  U[        U[        U5      S95      n
M     OU	n
U=(       d    U R                  U   nSU SU R                  U5       SU R                  U5       SU
 S	U S3nU R                  (       d  UR                  S
S5      (       a  U R                  R                  U5        U R                  U5        g)ay  
Core logging method that handles message formatting and output.

Args:
    level: Log level for this message
    message: Message template string
    tag: Tag for the message
    params: Parameters to format into the message
    colors: Color overrides for specific parameters
    boxes: Box overrides for specific parameters
    base_color: Base color for the entire message
Nr   z[[r   z]]z[/)type z [/force_verboseFr&   )rA   r   replaceformatitemsrs   r   r   r   r   r   r   r   printr   )r!   r   rM   rN   r   r   r   r   rQ   parsed_messageformatted_messagekeyrA   	value_str	color_strcolorlog_lines                    r"   _logAsyncLogger._log   s   . ;;--- !d3;;CF
 !/ 5 5 ? ?$lln
J..sD9AA#tL	cm"#FK=)Bv{m1 MI(9(A(A)(W% )I 5S\(9(A(A)*93u:F)H% - !/ %:E(:ugQt//45Qt~~c7J6K1M^L__bchbiijk <<6::ou==LLx( 	H%r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog a debug message.N)r   r   r,   rP   s       r"   rR   AsyncLogger.debug       		(..'9&9r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog an info message.Nr   r   r-   rP   s       r"   rV   AsyncLogger.info       		(--88r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog a success message.N)r   r   r.   rP   s       r"   rY   AsyncLogger.success       		(""G;F;r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog a warning message.N)r   r   r/   rP   s       r"   r\   AsyncLogger.warning   r   r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog a critical message.Nr   r   r0   rP   s       r"   criticalAsyncLogger.critical   r   r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog an exception message.Nr   rP   s       r"   	exceptionAsyncLogger.exception   r   r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog a fatal message.Nr   rP   s       r"   fatalAsyncLogger.fatal   r   r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog an alert message.Nr   rP   s       r"   alertAsyncLogger.alert  r   r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog a notice message.Nr   rP   s       r"   noticeAsyncLogger.notice  r   r%   c                 H    U R                   " [        R                  X40 UD6  g)zLog an error message.Nr   rP   s       r"   r_   AsyncLogger.error  r   r%   ra   rY   rb   rc   c           	      2   [        U5      nU R                  Xe5      nU R                  U(       a  [        R                  O[        R
                  SUUU(       a  SOSUS.U(       a  [        R                  O[        R
                  [        R                  S.S9  g)a   
Convenience method for logging URL fetch status.

Args:
    url: The URL being processed
    success: Whether the operation was successful
    timing: Time taken for the operation
    tag: Tag for the message
    url_length: Maximum length for URL in log
u%   {url} | {status} | ⏱: {timing:.2f}sr|   u   ✗)ra   statusrb   )r   rb   )r   rM   rN   r   r   N)r   r   r   r   r.   r0   r8   r/   )r!   ra   rY   rb   rN   rc   decoded_urlreadable_urls           r"   re   AsyncLogger.url_status  sv    $ cl}}[=		&-(""8>>;##*%  /6(**8>>"** 	 	
r%   r_   c                     [        U5      nU R                  XT5      nU R                  [        R                  SUXbS.S9  g)z
Convenience method for logging error status.

Args:
    url: The URL being processed
    error: Error message
    tag: Tag for the message
    url_length: Maximum length for URL in log
z{url} | Error: {error})ra   r_   )r   rM   rN   r   N)r   r   r   r   r0   )r!   ra   r_   rN   rc   r   r   s          r"   rh   AsyncLogger.error_status/  s?     cl}}[=		..,'8	 	 	
r%   )r   r   r   r   r   r   r   )z...)NNNNrj   rk   rl   rm   )r1   )r4   )r5   )r2   )r3   rn   ro   )r0   2   ))r'   r(   r)   r*   rC   r   r   r,   r8   r-   r.   r/   r0   r   r   rs   rv   r   rt   r   r   r   r   r   r   r	   r   rR   rV   rY   r\   r   r   r   r   r   r_   ru   re   rh   r6   r&   r%   r"   rx   rx   O   s   
 	 	%	
 	5 	E 	 	 	 	5 	5 	E 	 	% 	U  	!" 	5#M* 	x}}(**(**N #'&nn*.59S3-S S 	S
 S#X'S h012S S@5s 5s 57S 7S 7'9c 9 ,004%))-<&<& <& 	<&
 c3h(<& c8m,-<& S	"<& X&<&|:S :s :9C 9c 9<s < <<s < <: :# :: :3 ::S :s ::S :s :9c 9 9:S :s : !
!
 !
 	!

 !
 !
H KM

"
),
DG
 
r%   rx   c                       \ rS rSrSrS\4S jrS\S\S\4S jrSS\S\4S	 jjrSS\S\4S
 jjr	SS\S\4S jjr
SS\S\4S jjrSS\S\4S jjrSS\S\S\S\S\4
S jjrSS\S\S\S\4S jjrSrg)AsyncFileLoggeriD  zE
File-only asynchronous logger that writes logs to a specified file.
r   c                     Xl         [        R                  " [        R                  R	                  [        R                  R                  U5      5      SS9  g)zH
Initialize the file logger.

Args:
    log_file: File path for logging
Tr   N)r   r   r   r   r   r   )r!   r   s     r"   r   AsyncFileLogger.__init__I  s1     !
BGGOOBGGOOH$=>Nr%   r   rM   rN   c                     [         R                  " 5       R                  S5      SS n[        U R                  SSS9 nUR                  SU SU SU S	U S
3	5        SSS5        g! , (       d  f       g= f)z Write a message to the log file.r   Nr   r   r   r   r   z] [r   r   )r
   r   r   r   r   r   )r!   r   rM   rN   r   r   s         r"   r   AsyncFileLogger._write_to_fileS  se    LLN++,BCCRH	$--w71GGa	{#eWCuBwirBC 877s   A%%
A3c                 (    U R                  SX5        g)zLog a debug message to file.r,   Nr   rP   s       r"   rR   AsyncFileLogger.debugY      GW2r%   c                 (    U R                  SX5        g)zLog an info message to file.r-   Nr   rP   s       r"   rV   AsyncFileLogger.info]  s    FG1r%   c                 (    U R                  SX5        g)zLog a success message to file.r.   Nr   rP   s       r"   rY   AsyncFileLogger.successa      Iw4r%   c                 (    U R                  SX5        g)zLog a warning message to file.r/   Nr   rP   s       r"   r\   AsyncFileLogger.warninge  r  r%   c                 (    U R                  SX5        g)zLog an error message to file.r0   Nr   rP   s       r"   r_   AsyncFileLogger.errori  r  r%   ra   rY   rb   rc   c                 \    U(       a  SOSnUSU  SU SUS S3nU R                  SXt5        g)	zLog URL fetch status to file.r.   FAILEDNz... | Status: z	 | Time: z.2fs
URL_STATUSr   )r!   ra   rY   rb   rN   rc   r   rM   s           r"   re   AsyncFileLogger.url_statusm  s>    %8*%&nVHIfS\QRSL'7r%   r_   c                 <    USU  SU 3nU R                  SXS5        g)zLog error status to file.Nz... | Error: r0   r   )r!   ra   r_   rN   rc   rM   s         r"   rh   AsyncFileLogger.error_statuss  s*    *%&mE7;GW2r%   )r   Nrj   rk   rl   rm   rn   ro   rr   )r'   r(   r)   r*   rC   rs   r   r   rR   rV   rY   r\   r_   rt   ru   rv   re   rh   r6   r&   r%   r"   r   r   D  s    O ODC D# DC D3S 3s 32C 2c 25s 5 55s 5 53S 3s 38c 8D 8% 8c 8ad 83 3C 3c 3QT 3 3r%   r   )abcr   r   enumr   typingr   r   r   r	   r   r
   urllib.parser   rich.consoler   	rich.textr   utilsr   r   rs   r8   rK   rx   r   r&   r%   r"   <module>r     sd    #  , , 	       %!t !"sD (c <s
/ s
j23o 23r%   