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
(self, parameter_s='')
| 37 | |
| 38 | @line_magic |
| 39 | def logstart(self, parameter_s=''): |
| 40 | """Start logging anywhere in a session. |
| 41 | |
| 42 | %logstart [-o|-r|-t|-q] [log_name [log_mode]] |
| 43 | |
| 44 | If no name is given, it defaults to a file named 'ipython_log.py' in your |
| 45 | current directory, in 'rotate' mode (see below). |
| 46 | |
| 47 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
| 48 | history up to that point and then continues logging. |
| 49 | |
| 50 | %logstart takes a second optional parameter: logging mode. This can be one |
| 51 | of (note that the modes are given unquoted): |
| 52 | |
| 53 | append |
| 54 | Keep logging at the end of any existing file. |
| 55 | |
| 56 | backup |
| 57 | Rename any existing file to name~ and start name. |
| 58 | |
| 59 | global |
| 60 | Append to a single logfile in your home directory. |
| 61 | |
| 62 | over |
| 63 | Overwrite any existing log. |
| 64 | |
| 65 | rotate |
| 66 | Create rotating logs: name.1~, name.2~, etc. |
| 67 | |
| 68 | Options: |
| 69 | |
| 70 | -o |
| 71 | log also IPython's output. In this mode, all commands which |
| 72 | generate an Out[NN] prompt are recorded to the logfile, right after |
| 73 | their corresponding input line. The output lines are always |
| 74 | prepended with a '#[Out]# ' marker, so that the log remains valid |
| 75 | Python code. |
| 76 | |
| 77 | Since this marker is always the same, filtering only the output from |
| 78 | a log is very easy, using for example a simple awk call:: |
| 79 | |
| 80 | awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py |
| 81 | |
| 82 | -r |
| 83 | log 'raw' input. Normally, IPython's logs contain the processed |
| 84 | input, so that user lines are logged in their final form, converted |
| 85 | into valid Python. For example, %Exit is logged as |
| 86 | _ip.run_line_magic("Exit"). If the -r flag is given, all input is logged |
| 87 | exactly as typed, with no transformations applied. |
| 88 | |
| 89 | -t |
| 90 | put timestamps before each input line logged (these are put in |
| 91 | comments). |
| 92 | |
| 93 | -q |
| 94 | suppress output of logstate message when logging is invoked |
| 95 | """ |
| 96 |