
    e!h                         d Z ddlmZ ddl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 Zd Zd Zdd	Z G d
 de      Z G d de      Zy)zE
Helpers for logging.

This module needs much love to become useful.
    )print_functionN   )mkdirpc                 b    t         j                  j                  d      rt        d| dz
        S | S )zRemove .1s to the time under Windows: this is the time it take to
    stat files. This is needed to make results similar to timings under
    Unix, for tests
    winr   g?)sysplatform
startswithmaxts    U/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/joblib/logger.py_squeeze_timer      s+    
 ||u%1a#g    c                 ,    t        |       } d| | dz  fz  S )Nz%.1fs, %.1fmin      N@r   r   s    r   format_timer   "   s    aAq!d(m++r   c                 <    t        |       } | dkD  rd| dz  z  S d| z  S )N<   z%4.1fminr   z %5.1fsr   r   s    r   short_format_timer   '   s,    aA2vQX&&Ar   c                     dt         j                  v r)dd l}|j                         }|j	                  ddd       nd }t        j                  | ||      }|r j                  di | |S )	Nnumpyr      @   r   )	precision	threshold	edgeitems)depthindent )r   modulesr   get_printoptionsset_printoptionspprintpformat)objr    r   npprint_optionsouts         r   r&   r&   /   sf    #++++-
a2C
..E&
9C,m,Jr   c                   2    e Zd ZdZddZd Zd Zd Zd	dZy)
Loggerz Base class for logging messages.Nc                 4    || _         |r|| _        yd| _        y)z
        Parameters
        ----------
        depth: int, optional
            The depth of objects printed.
        name: str, optional
            The namespace to log to. If None, defaults to joblib.
        joblibN)r   _name)selfr   names      r   __init__zLogger.__init__C   s     
!T
x
r   c                 l    t        j                  | j                        j                  d| d|       y N[z]: )logging	getLoggerr/   warningr0   msgs     r   warnzLogger.warnO   s$    $**%--D#.FGr   c                 :    t        j                  d| d|       y r4   )r6   infor9   s     r   r=   zLogger.infoR   s    4-.r   c                 l    t        j                  | j                        j                  d| d|       y r4   )r6   r7   r/   debugr9   s     r   r?   zLogger.debugU   s$    $**%++$,DEr   c                 2    t        ||| j                        S )z2Return the formatted representation of the object.)r    r   )r&   r   )r0   r'   r    s      r   formatzLogger.formatY   s    s6<<r   )   N)r   )	__name__
__module____qualname____doc__r2   r;   r=   r?   rA   r!   r   r   r,   r,   @   s     *
0H/F=r   r,   c                        e Zd ZdZddZddZy)	PrintTimez3Print and log messages while keeping track of time.Nc                    ||t        d      t        j                         | _        | j                  | _        | t        j
                  j                  |d      }|| _        |t        t        j
                  j                  |             t        j
                  j                  |      rQt        dd      D ](  }	 t        j                  |d|z  z   |d|dz   z  z          * 	 t        j                  ||dz          	 t        |d      5 }|j!                  d       |j!                  d	t        j"                  | j                        z         d d d        y y #  Y xY w#  Y exY w# 1 sw Y   y xY w#  Y y xY w)
Nz&Cannot specify both logfile and logdirz
joblib.logr   	   z.%iz.1wz
Logging joblib python script
z

---%s---
)
ValueErrortime	last_time
start_timeospathjoinlogfiler   dirnameexistsrangeshutilmovecopyopenwritectime)r0   rS   logdiris       r   r2   zPrintTime.__init__d   sQ   6#5EFF..ggll6<8G277??7+,ww~~g&q! 1A1Geai$75APQE?9RS1-KK48'3' O7MM"DEMM.4::dnn3M"MNO O! 10
-,O OsC   <%E$E >E1 
AE%E1 EE"%E.*E1 .E1 1E5c                    |s2t        j                          | j                  z
  }|dt        |      }n,t        j                          | j                  z
  }d|||dz  fz  }t	        |t
        j                         | j                  -	 t        | j                  d      5 }t	        ||       ddd       t        j                          | _        y# 1 sw Y   #xY w#  Y *xY w)zmPrint the time elapsed between the last call and the current
        call, with an optional message.
        z: z%s: %.2fs, %.1f minr   )fileNa)	rM   rN   r   rO   printr   stderrrS   rZ   )r0   r:   total
time_lapsefull_msgfs         r   __call__zPrintTime.__call__   s     t~~5J#&J(?@H t6J,Zb/QQHhSZZ(<<#$,,, ,(+, , ,s$   	C C-C CC C)NN) F)rC   rD   rE   rF   r2   rh   r!   r   r   rH   rH   a   s    = H%r   rH   )r   rB   )rF   
__future__r   r6   rP   r%   rW   r   rM   diskr   r   r   r   r&   objectr,   rH   r!   r   r   <module>rm      sQ    &  	   
  ,
"=V =B>% >%r   