o
    Zh                      @   sR   d Z ddlZddlZddlZddlZddlZedej G dd de	Z
dS )z/Logger class for IPython's logging facilities.
    NZparsoc                   @   st   e Zd ZdZ		dddZdd Zd	d
 ZeeeZ		dddZ	dd Z
dd Zdd ZdddZdd ZeZdS )Loggerz9A Logfile class with different policies for file creation
Logger.log overc                 C   s:   || _ || _|| _|| _d | _d| _d| _d| _d| _d S )NF)	home_dirlogfnamelogheadlogmodelogfilelog_raw_input
log_output	timestamp
log_active)selfr   r   r   r	    r   J/var/www/html/lang_env/lib/python3.10/site-packages/IPython/core/logger.py__init__!   s   
zLogger.__init__c                 C   s   |dvr
t d| || _d S )N)appendbackupglobalr   rotatezinvalid log mode %s given)
ValueError_logmode)r   moder   r   r   	_set_mode:   s   
zLogger._set_modec                 C   s   | j S )N)r   r   r   r   r   	_get_mode?   s   zLogger._get_modeNFc                 C   s  | j durtd| j |dur|| _|dur|| _|dur!|| _|| _|| _|| _tj	j
}| j}|dkr@tj| jddd| _ n|dkri|| jr^| jd }||rWt| t| j| tj| jd	dd| _ n|d
krtj	| j| j| _tj| jddd| _ nv|dkr|| jrt| j tj| jd	dd| _ n\|dkr|| jr|| jd rt| jd }	|	  |	  |	D ]%}
tj	|
\}}t|dd d }t|
|d t|d d  qt| j| jd  tj| jd	dd| _ |dkr| j | j | j   d| _dS )zoGenerate a new log-file with a default header.

        Raises RuntimeError if the log has already been startedNzLog file is already active: %sr   azutf-8)encodingr   ~wr   r   r   z.001~z.*~   .   T)r
   RuntimeErrorr   r   r	   r   r   r   ospathisfileioopenremoverenamejoinr   globsortreversesplitextintreprzfillwriteflushr   )r   r   r   r	   r   r   r   r(   Zbackup_lognameoldfrootextnumr   r   r   logstartD   sX   





$


zLogger.logstartc                 C   sx   |dvr
t d| ddddd}| jdu rtd dS | j|kr*td||  dS td	||  | j | _| j| _dS )
z4Switch logging on/off. val should be ONLY a boolean.)FTr   r!   z:Call switch_log ONLY with a boolean argument, not with: %sZOFFON)r   r!   FTNz
Logging hasn't been started yet (use logstart for that).

%logon/%logoff are for temporarily starting and stopping logging for a logfile
which already exists. But you must first start the logging process with
%logstart (optionally giving a logfile name).zLogging is alreadyzSwitching logging)r   r
   printr   Zlog_active_out)r   vallabelr   r   r   
switch_log   s   


zLogger.switch_logc                 C   sn   | j du rtd dS | jrdpd}td| j td| j td| j td| j td	| j td
| dS )z(Print a status message about the logger.NzLogging has not been activated.activeztemporarily suspendedzFilename       :zMode           :zOutput logging :zRaw input log  :zTimestamping   :zState          :)r
   r>   r   r   r	   r   r   r   )r   stater   r   r   logstate   s   
zLogger.logstatec                 C   s"   | j r
| | dS | | dS )a^  Write the sources to a log.

        Inputs:

        - line_mod: possibly modified input, such as the transformations made
          by input prefilters or input handlers of various kinds. This should
          always be valid Python.

        - line_ori: unmodified input line from the user. This is not
          necessarily valid Python.
        N)r   	log_write)r   Zline_modZline_orir   r   r   log   s   inputc                 C   s   | j r\|r^| jj}|dkr| jr|tdt  || n|dkr8| jr8ddd |	 D }|d|  z| j
  W dS  ty[   td td	| j d
 td Y dS w dS dS )z%Write data to the log file, if activerG   z# %a, %d %b %Y %H:%M:%S
output
c                 S   s   g | ]}d | qS )z
#[Out]# %sr   ).0sr   r   r   
<listcomp>   s    z$Logger.log_write.<locals>.<listcomp>z%s
zFailed to flush the log file.zPlease check that z' exists and have the right permissions.zHAlso consider turning off the log with `%logstop` to avoid this warning.N)r   r
   r5   r   timestrftime	localtimer   r-   
splitlinesr6   OSErrorr>   r   )r   datakindr5   odatar   r   r   rE      s.   



zLogger.log_writec                 C   s.   | j dur| j   d| _ ntd d| _dS )zFully stop logging and close log file.

        In order to start logging again, a new logstart() call needs to be
        made, possibly (though not necessarily) with a new filename, mode and
        other options.NzLogging hadn't been started.F)r
   closer>   r   r   r   r   r   logstop   s
   


zLogger.logstop)r   r   r   )NNNFFF)rG   )__name__
__module____qualname____doc__r   r   r   propertyr	   r<   rA   rD   rF   rE   rV   Z	close_logr   r   r   r   r      s"    


A
r   )rZ   r.   r)   loggingr&   rM   	getLoggersetLevelWARNINGobjectr   r   r   r   r   <module>   s    