Format: application/x-python-code
⬇ Download File (5.5 KB)
   1  o
   2  
   3  ��h� �@sRdZddlZddlZddlZddlZddlZe�d��ej�Gdd�de	�Z
   4  dS)z/Logger class for IPython's logging facilities.
   5  �NZparsoc@steZdZdZ		ddd�Zdd�Zd	d
   6  �Zeee�Z		dd
   7  d�Z	dd�Z
   8  dd�Zdd�Zddd�Z
   9  dd�ZeZdS)�Loggerz9A Logfile class with different policies for file creation�
  10  Logger.log��overcCs:||_||_||_||_d|_d|_d|_d|_d|_dS)NF)	�home_dir�logfname�loghead�logmode�logfile�
  11  log_raw_input�
  12  log_output�	timestamp�
  13  log_active)�selfrrrr	�r�Ic:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/logger.py�__init__!s
  14  zLogger.__init__cCs|dvr
  15  td|��||_dS)N)�append�backup�globalr�rotatezinvalid log mode %s given)�
  16  ValueError�_logmode)r�moderrr�	_set_mode:s
  17  zLogger._set_modecCs|jS)N)r�rrrr�	_get_mode?szLogger._get_modeNFcCs|jdurtd|j��|dur||_|dur||_|dur!||_||_||_||_tj	j
  18  }|j}|dkr@tj|jddd�|_n�|dkri||j�r^|jd}||�rWt�
  19  |�t�|j|�tj|jd	dd�|_n�|d
  20  kr�tj	�|j|j�|_tj|jddd�|_nv|dkr�||j�r�t�
  21  |j�tj|jd	dd�|_n\|dkr�||j�r�||jd
  22  �r�t�|jd�}	|	��|	��|	D]%}
  23  tj	�|
  24  �\}}t|dd��d}
  25  t�|
  26  |dt|
  27  ��d�d�q�t�|j|jd
  28  �tj|jd	dd�|_|dk�r|j�|j�|j��d|_dS)zoGenerate a new log-file with a default header.
  29  
  30          Raises RuntimeError if the log has already been startedNzLog file is already active: %sr�azutf-8)�encodingr�~�wrrrz.001~z.*~�������.�T)r
  31  �RuntimeErrorrrr	r
  32  rr�os�path�isfile�io�open�remove�rename�joinr�glob�sort�reverse�splitext�int�repr�zfill�write�flushr)rrrr	rr
  33  rr(Zbackup_logname�old�f�root�ext�numrrr�logstartDsX
  34  �
  35  
  36  
  37  
  38  
  39  $
  40  
  41  
  42  zLogger.logstartcCsx|dvr
  43  td|��ddddd�}|jdurtd�dS|j|kr*td||�dStd	||�|j|_|j|_dS)
  44  z4Switch logging on/off. val should be ONLY a boolean.)FTrr!z:Call switch_log ONLY with a boolean argument, not with: %sZOFF�ON)rr!FTNz�
  45  Logging hasn't been started yet (use logstart for that).
  46  
  47  %logon/%logoff are for temporarily starting and stopping logging for a logfile
  48  which already exists. But you must first start the logging process with
  49  %logstart (optionally giving a logfile name).zLogging is alreadyzSwitching logging)rr
  50  �printrZlog_active_out)r�val�labelrrr�
  51  switch_log�s�
  52  
  53  
  54  zLogger.switch_logcCsn|jdurtd�dS|jrdpd}td|j�td|j�td|j�td|j�td	|j�td
  55  |�dS)z(Print a status message about the logger.NzLogging has not been activated.�activeztemporarily suspendedzFilename       :zMode           :zOutput logging :zRaw input log  :zTimestamping   :zState          :)r
  56  r>rrr	rrr
  57  )r�staterrr�logstate�s
  58  zLogger.logstatecCs"|jr
  59  |�|�dS|�|�dS)a^Write the sources to a log.
  60  
  61          Inputs:
  62  
  63          - line_mod: possibly modified input, such as the transformations made
  64            by input prefilters or input handlers of various kinds. This should
  65            always be valid Python.
  66  
  67          - line_ori: unmodified input line from the user. This is not
  68            necessarily valid Python.
  69          N)r�	log_write)rZline_modZline_orirrr�log�s�inputcCs�|jr\|r^|jj}|dkr|jr|t�dt����||�n|dkr8|jr8d�dd�|�	�D��}|d|�z|j�
  70  �WdSty[td�td	|j
  71  �d
  72  ��td�YdSwdSdS)
  73  z%Write data to the log file, if activerGz# %a, %d %b %Y %H:%M:%S
  74  �output�
  75  cSsg|]}d|�qS)z
  76  #[Out]# %sr)�.0�srrr�
  77  <listcomp>�s�z$Logger.log_write.<locals>.<listcomp>z%s
  78  zFailed to flush the log file.zPlease check that z' exists and have the right permissions.zHAlso consider turning off the log with `%logstop` to avoid this warning.N)rr
  79  r5r
  80  �time�strftime�	localtimerr-�
  81  splitlinesr6�OSErrorr>r)r�data�kindr5�odatarrrrE�s.
  82  
  83  
  84  ��
  85  ���zLogger.log_writecCs.|jdur|j��d|_ntd�d|_dS)z�Fully stop logging and close log file.
  86  
  87          In order to start logging again, a new logstart() call needs to be
  88          made, possibly (though not necessarily) with a new filename, mode and
  89          other options.NzLogging hadn't been started.F)r
  90  �closer>rrrrr�logstop�s
  91  
  92  
  93  
  94  zLogger.logstop)rrr)NNNFFF)rG)�__name__�
  95  __module__�__qualname__�__doc__rrr�propertyr	r<rArDrFrErVZ	close_logrrrrrs"
  96  �
  97  
  98  �A
  99  r)rZr.r)�loggingr&rM�	getLogger�setLevel�WARNING�objectrrrrr�<module>s