2012-08-06 13 views
9

Gibt es eine Möglichkeit, die Protokollierungsfunktion von IPython mit Ausgabe und Eingabe zu versehen?IPython-Ausgabe protokollieren?

Dies ist, was eine Protokolldatei wie zur Zeit aussieht:

#!/usr/bin/env python 
# 2012-08-06.py 
# IPython automatic logging file 
# 12:02 
# ================================= 
print "test" 

würde ich eine mehr anzeigen Linie haben wollen up:

#!/usr/bin/env python 
# 2012-08-06.py 
# IPython automatic logging file 
# 12:02 
# ================================= 
print "test" 
# test 

(die # ist, weil ich davon aus, dass benötigt wird, zu verhindern, dass IPython logplay Funktion zu brechen)

Ich nehme an, das ist möglich mit IPython-Notebooks, aber auf mindestens einer Maschine, ich brauche das für, ich bin Limit ed zu ipython 0.10.2.

EDIT: Ich würde gerne wissen, wie dies automatisch einzurichten, d. H. In der Konfigurationsdatei. Gerade jetzt meine Config sieht aus wie

from time import strftime 
import os 
logfilename = strftime('ipython_log_%Y-%m-%d')+".py" 
logfilepath = "%s/%s" % (os.getcwd(),logfilename) 

file_handle = open(logfilepath,'a') 
file_handle.write('########################################################\n') 
out_str = '# Started Logging At: '+ strftime('%Y-%m-%d %H:%M:%S\n') 
file_handle.write(out_str) 
file_handle.write('########################################################\n') 
file_handle.close() 

c.TerminalInteractiveShell.logappend = logfilepath 
c.TerminalInteractiveShell.logstart = True 

aber c.TerminalInteractiveShell.log_output = True scheint spezifiziert zu haben keinen Einfluss

Antwort

8

Es gibt die -o Option für %logstart:

-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. 

NACHTRAG: Wenn Sie in einer interaktiven ipython Sitzung sind für welche Protokollierung bereits gestartet wurde, müssen Sie zuerst die Protokollierung stoppen und dann neu starten:

In [1]: %logstop 

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

Beachten Sie, dass nach dem Neustart "Output Logging" jetzt "True" ist.

+1

Die Lösung scheint dies in einem Startskript zu tun, wie hier beschrieben: http://wiki.ipython.org/Cookbook/DatedLog (das war die Lösung in http://stackoverflow.com/questions/11836612/wo-wie-in-was-kontext-ist-ipythons-konfigurationsdatei ausgeführt? lq = 1) – keflavich