I would like to always log ipython commandline and output to a file in append mode. On reading the file under .ipython/profile_default/startup README
$ cat README
This is the IPython startup directory
.py and .ipy files in this directory will be run *prior* to any code or files specified
via the exec_lines or exec_files configurables whenever you load this profile.
Files will be run in lexicographical order, so you can control the execution order of files
with a prefix, e.g.::
00-first.py
50-middle.py
99-last.ipy
I tried adding a file first.py with below contents
logstart -o -r -t logs/ipython.log 'append'
logstart is a magic command. I am getting below error when I am trying to start ipython
File "/home/mtk/.ipython/profile_default/startup/00-first.py", line 1
logstart -o -r -t logs/ipython.log 'append'
^
SyntaxError: invalid syntax
How to resolve this issue?
1 Answer 1
"Thomas K" comment also looks like a solution, but here is different solution that I found myself
As he stated correct, we can only have python code in *.py file in the startup folder, I replaced my earlier text with below. Magic commands can be invoked using run_line_magic method
get_ipython().run_line_magic(u"logstart", u"-o -r /home/mt/Dropbox/a/logs/ipython_log.py append")
get_ipython().run_line_magic(u"logstate", "")
.ipyextension..pyfiles have to be regular Python code, without IPython special syntax.