[IPython-dev] Logging commands using the %logstart magic

Phil Elson pelson.pub at gmail.com
Mon Nov 17 11:47:24 EST 2014


I'm trying to replicate functionality found in IDL which generates
something called "journal" files. Journal files in IDL are essentially a
log of commands alongside the (commented out) output and themselves produce
valid code.

IPython's %logstart with the "-o" flag is almost exactly what I need,
except it doesn't seem to record standard out (only IPython out):

> ipython
Python 2.7.6
IPython 2.2.0 -- An enhanced Interactive Python.

In [1]: %logstart -o testing_logging.py
Activating auto-logging. Current session state plus future input saved.
Filename       : testing_logging.py
Mode           : backup
Output logging : True
Raw input log  : False
Timestamping   : False
State          : active

In [2]: print 'Hello logging world non-IPython out!'
Hello logging world non-IPython out!

In [3]: 'Hello logging world IPython out!'
Out[3]: 'Hello logging world IPython out!'

In [4]: exit

The resulting file looks like:

# IPython log file

print 'Hello logging world non-IPython out!'
'Hello logging world IPython out!'
#[Out]# 'Hello logging world IPython out!'
exit()

Essentially I'd like the contents of the second input to be recorded as it
is for the third.

Before I go hacking around with the magic and sys.stdout, does anybody have
a quick solution to this?

Thanks,

Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141117/6f09424a/attachment.html>


More information about the IPython-dev mailing list