[Tutor] Logging script output
Alan Gauld
alan.gauld at btinternet.com
Sun Dec 15 19:07:30 CET 2013
On 15/12/13 17:43, Reuben wrote:
> Hi,
>
> What is the best way to log the output of a python script execution.
Best is always going to be subjective and depend
on a lot of parameters.
It might be that the best way of capturing the output
is to use file redirection:
$ python myscript.py > logfile.txt
or if you need to see it as well pipe it into tee (Unix only):
$ python myscript.py | tee logfile.txt
But if you need more sophistication you might want to do the redirection
in your code, or add some logging print/write statements
> Do we need to use the logging module of python?
Probably not but it is another option.
It all depends on exactly what, and how much, and for how long,
you want to log. And how you want to run the program. And how the
program displays its output (a GUI or web pages?)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list