
    ^h                     d    S r SSKrSSKrSSKJrJrJr  SSKJr  SSK	J
r
  \ " S S\5      5       rg)z=Implementation of magic functions for IPython's own logging.
    N)Magicsmagics_class
line_magic)warn)Boolc                       \ rS rSrSr\" SSS9R                  SS9r\SS j5       r	\SS	 j5       r
\SS
 j5       r\SS j5       r\SS j5       rSrg)LoggingMagics   z(Magics related to all logging machinery.FzF
        Suppress output of log state when logging is enabled
        )helpT)configc                    U R                  US5      u  p#SU;   nSU;   nSU;   nSU;   nU R                  R                  nU(       a   UR                  5       u  pOUR                  n	UR
                  n
U R                  R                  nU	(       a  [        R                  R                  U	5      n	XR                  l        Sn UR                  XXUU5        U(       a  SUl        U(       a!  U R                  R                  R                  nO U R                  R                  R                  nU(       a  UR                  nU R                  R                  R                   n[#        S	[%        U5      S	-
  5       H<  nU" UU   R'                  5       S
-   5        UU;   d  M'  U" [)        UU   5      S5        M>     O4UR                  S
R+                  US	S 5      5        UR                  S
5        U(       a  SUl        U R,                  (       d$  U(       d  [/        S5        UR1                  5         ggg!   Un	Sn
 GN= f!   XR                  l        [3        S[4        R6                  " 5       S	   -  5         g= f)a  Start logging anywhere in a session.

%logstart [-o|-r|-t|-q] [log_name [log_mode]]

If no name is given, it defaults to a file named 'ipython_log.py' in your
current directory, in 'rotate' mode (see below).

'%logstart name' saves to file 'name' in 'backup' mode.  It saves your
history up to that point and then continues logging.

%logstart takes a second optional parameter: logging mode. This can be one
of (note that the modes are given unquoted):

append
    Keep logging at the end of any existing file.

backup
    Rename any existing file to name~ and start name.

global
    Append to  a single logfile in your home directory.

over
    Overwrite any existing log.

rotate
    Create rotating logs: name.1~, name.2~, etc.

Options:

  -o
    log also IPython's output. In this mode, all commands which
    generate an Out[NN] prompt are recorded to the logfile, right after
    their corresponding input line. The output lines are always
    prepended with a '#[Out]# ' marker, so that the log remains valid
    Python code.

  Since this marker is always the same, filtering only the output from
  a log is very easy, using for example a simple awk call::

    awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py

  -r
    log 'raw' input.  Normally, IPython's logs contain the processed
    input, so that user lines are logged in their final form, converted
    into valid Python.  For example, %Exit is logged as
    _ip.magic("Exit").  If the -r flag is given, all input is logged
    exactly as typed, with no transformations applied.

  -t
    put timestamps before each input line logged (these are put in
    comments).

  -q 
    suppress output of logstate message when logging is invoked
ortqortqbackupz# IPython log file

F   
outputNTzGActivating auto-logging. Current session state plus future input saved.zCouldn't start log: %s)parse_optionsshellloggersplitlogfnamelogmodelogfileospath
expanduserlogstart	timestamphistory_managerinput_hist_rawinput_hist_parsed	log_writeoutput_histrangelenrstripreprjoinquietprintlogstater   sysexc_info)selfparameter_soptspar
log_outputlog_raw_inputr"   r-   r   r   r   old_logfileloghead
input_histr&   r'   ns                    U/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/magics/logging.pyr!   LoggingMagics.logstart&   s   v %%k&9D[
t4K	t"" ##&99; 
 HnnG jj((ww))(3H%

+%	"OOHwI)+  $) !ZZ77FF
!ZZ77II
",,	"jj88DDqZ!23Ajm224u<=K'!${1~"6x@ 4
   JqrN!;<  '#' JJ% H I! #(Jc#" 	?!,JJ)CLLN1,==>s   H/ H; /H8;6I3c                 L    U R                   R                  R                  5         g)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.N)r   r   logstopr2   r3   s     r<   r?   LoggingMagics.logstop   s     	

!!#    c                 N    U R                   R                  R                  S5        g)zDTemporarily stop logging.

You must have previously started logging.r   Nr   r   
switch_logr@   s     r<   logoffLoggingMagics.logoff   s    
 	

$$Q'rB   c                 N    U R                   R                  R                  S5        g)zRestart logging.

This function is for restarting logging which you've temporarily
stopped with %logoff. For starting logging for the first time, you
must use the %logstart function, which allows you to specify an
optional log filename.r   NrD   r@   s     r<   logonLoggingMagics.logon   s     	

$$Q'rB   c                 L    U R                   R                  R                  5         g)z'Print the status of the logging system.N)r   r   r/   r@   s     r<   r/   LoggingMagics.logstate   s     	

""$rB    N) )__name__
__module____qualname____firstlineno____doc__r   tagr-   r   r!   r?   rF   rI   r/   __static_attributes__rM   rB   r<   r	   r	      s    2	 
cc	 
 {" {"z $ $ ( ( ( ( % %rB   r	   )rS   r   r0   IPython.core.magicr   r   r   warningsr   	traitletsr   r	   rM   rB   r<   <module>rY      s?    
 
 @ ?   f%F f% f%rB   