Logging output from python

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Dec 7 22:47:05 EST 2006


At Thursday 7/12/2006 23:21, Cameron Walsh wrote:

> > Here is my problem. I want to log everything displayed in the screen
> > after I start the main python script. Things include unhandled
> > exceptions , message from print statement and other sources.
> > Basically, if it is displayed on the screen, I want to log it..
>
>If it's on linux you can just redirect the screen output to a file:
>
>python initialfile.py 1>stdout.txt 2>stderr.txt
>[...]
>
>As for windows, I'll test it now...
>
>It turns out you can at least redirect the output to a file, I'm not
>sure what it does with standard error or even if it exists or not.
>
>python initialfile.py > output.txt

It's the same syntax as noted for linux above. 1> is the same as > alone.

If ALL the testing is done on a single program (that is, no os.system 
or spawn or subprocess...) then you could just replace sys.stdout and 
sys.stderr with another open file (or file-like) object.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



More information about the Python-list mailing list