Format: application/x-python-code
⬇ Download File (5.1 KB)
   1  o
   2  
   3  ��h��@sXdZddlZddlZddlmZmZmZddlmZddl	m
   4  Z
   5  eGdd�de��ZdS)z=Implementation of magic functions for IPython's own logging.
   6  �N)�Magics�magics_class�
   7  line_magic)�warn)�Boolc@sjeZdZdZeddd�jdd�Zeddd	��Zedd
   8  d��Z	eddd
   9  ��Z
  10  eddd��Zeddd��ZdS)�
  11  LoggingMagicsz(Magics related to all logging machinery.FzF
  12          Suppress output of log state when logging is enabled
  13          )�helpT)�config�cCs�|�|d�\}}d|v}d|v}d|v}d|v}|jj}|r0z|��\}	}
  14  Wn|}	d}
  15  Yn|j}	|j}
  16  |jj}|	rBtj�	|	�}	|	|j_d}z|�
  17  |	||
  18  |||�Wn||j_tdt�
  19  �d	�Yd
  20  S|rnd
  21  |_|rv|jjj}
  22  n|jjj}
  23  |r�|j}|jjj}td	t|
  24  �d	�D]}||
  25  |��d�||vr�|t||�d�q�n|�d�|
  26  d	d
  27  ���|�d�|r�d|_|js�|s�td�|��d
  28  Sd
  29  Sd
  30  S)a�Start logging anywhere in a session.
  31  
  32          %logstart [-o|-r|-t|-q] [log_name [log_mode]]
  33  
  34          If no name is given, it defaults to a file named 'ipython_log.py' in your
  35          current directory, in 'rotate' mode (see below).
  36  
  37          '%logstart name' saves to file 'name' in 'backup' mode.  It saves your
  38          history up to that point and then continues logging.
  39  
  40          %logstart takes a second optional parameter: logging mode. This can be one
  41          of (note that the modes are given unquoted):
  42  
  43          append
  44              Keep logging at the end of any existing file.
  45  
  46          backup
  47              Rename any existing file to name~ and start name.
  48  
  49          global
  50              Append to  a single logfile in your home directory.
  51  
  52          over
  53              Overwrite any existing log.
  54  
  55          rotate
  56              Create rotating logs: name.1~, name.2~, etc.
  57  
  58          Options:
  59  
  60            -o
  61              log also IPython's output. In this mode, all commands which
  62              generate an Out[NN] prompt are recorded to the logfile, right after
  63              their corresponding input line. The output lines are always
  64              prepended with a '#[Out]# ' marker, so that the log remains valid
  65              Python code.
  66  
  67            Since this marker is always the same, filtering only the output from
  68            a log is very easy, using for example a simple awk call::
  69  
  70              awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py
  71  
  72            -r
  73              log 'raw' input.  Normally, IPython's logs contain the processed
  74              input, so that user lines are logged in their final form, converted
  75              into valid Python.  For example, %Exit is logged as
  76              _ip.run_line_magic("Exit").  If the -r flag is given, all input is logged
  77              exactly as typed, with no transformations applied.
  78  
  79            -t
  80              put timestamps before each input line logged (these are put in
  81              comments).
  82  
  83            -q
  84              suppress output of logstate message when logging is invoked
  85          Zortq�o�r�t�q�backupz# IPython log file
  86  
  87  zCouldn't start log: %s�F�
  88  �outputNTzGActivating auto-logging. Current session state plus future input saved.)Z
  89  parse_options�shell�logger�split�logfname�logmodeZlogfile�os�path�
  90  expanduser�logstartr�sys�exc_info�	timestampZhistory_managerZinput_hist_rawZinput_hist_parsed�	log_write�output_hist�range�len�rstrip�repr�join�quiet�print�logstate)�self�parameter_s�opts�parZ
  91  log_outputZ
  92  log_raw_inputrr&rrrZold_logfileZlogheadZ
  93  input_histrr �n�r.�Qc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/magics/logging.pyr&s`;�
  94  
  95  ��
  96  
  97  �zLoggingMagics.logstartcC�|jj��dS)z�Fully stop logging and close log file.
  98  
  99          In order to start logging again, a new %logstart call needs to be made,
 100          possibly (though not necessarily) with a new filename, mode and other
 101          options.N)rr�logstop�r)r*r.r.r/r1�szLoggingMagics.logstopcC�|jj�d�dS)zLTemporarily stop logging.
 102  
 103          You must have previously started logging.rN�rrZ
 104  switch_logr2r.r.r/�logoff�szLoggingMagics.logoffcCr3)aRestart logging.
 105  
 106          This function is for restarting logging which you've temporarily
 107          stopped with %logoff. For starting logging for the first time, you
 108          must use the %logstart function, which allows you to specify an
 109          optional log filename.rNr4r2r.r.r/�logon�s	zLoggingMagics.logoncCr0)z'Print the status of the logging system.N)rrr(r2r.r.r/r(�szLoggingMagics.logstateN)r
 110  )
 111  �__name__�
 112  __module__�__qualname__�__doc__r�tagr&rrr1r5r6r(r.r.r.r/rs"��}
 113  r)r:rrZIPython.core.magicrrr�warningsrZ	traitletsrrr.r.r.r/�<module>s