[Tutor] Logging stdout and stderr
kent37 at tds.net
Sat Jun 18 13:36:29 CEST 2005
Connor.Smith at huntington.com wrote:
> Hi there -
> I'm trying to log the results of a command that I'm running via the
> popen2 module to a file, while at the same time displaying its progress
> on the screen. So, at the end of the run, I should have the entire
> output (stdout and stderr) on the screen, but also have two file objects
> each with the contents of one of stdout and stderr.
You could do this with the logging package. Set up the logger to log to the screen and to a file. You could split the files by log level or (I think) by using two different loggers.
For what you are doing this is probably overkill (Hugo's suggestion is simpler) but if you have output in many places in the file logging is a good solution. Also it lets you for example put debug messages in the file but not on screen.
More information about the Tutor