[IPython-user] logstart -o ???

Fernando Perez fperez.net@gmail....
Mon Nov 26 01:11:31 CST 2007


Hi John,

On Jul 1, 2007 4:09 PM, John <jl_.+2@redwoodscientific.com> wrote:
> How can you turn on output logging (logstart -o) from within a
> session after logging has already started?
>
>   In [40]: %logstart -o
>   WARNING: Couldn't start log: Log file is already active: ipython_log.py

There's no public API do that directly, but with current SVN, you can
stop logging altogether and restart it:


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

In [2]: print 1
1

In [3]: logstate
Filename       : ipython_log.py
Mode           : rotate
Output logging : False
Raw input log  : False
Timestamping   : False
State          : active

In [4]: logstop

In [5]: logstate
Logging has not been activated.

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


Additionally, if you really just need to hackishly modify the output
logging behavior on the fly, you can always flip that flag manually.
For example, if you were logging without output, this will activate
it:

In [4]: __IP.logger.log_output = True

Notice how now output will be logged:

In [5]: 3+4
Out[5]: 7

In [6]: !cat ipython_log.py
#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
#log# opts = Struct({'__allownew': True, 'logfile': 'ipython_log.py'})
#log# args = []
#log# It is safe to make manual edits below here.
#log#-----------------------------------------------------------------------
_ip.magic("logstart ")

3+4
_ip.system("cat ipython_log.py")
__IP.logger.log_output = True
3+4
#[Out]# 7
_ip.system("cat ipython_log.py")


HTH,

f


More information about the IPython-user mailing list