Just wanted to pick your brains on this. I have several subprocesses running and I wanted to print the stderr and stdout to a file. I've done this so far:
def write_to_stderr_log(process):
    stderr= open("stderr.log", "w")
    proc_err = process.communicate()
    print >> stderr, proc_err
    stderr.close()
def write_to_stdout_log(process):
    stdout = open("stdout.log", "w")
    proc_out = process.communicate()
    print >> stdout, proc_out
    stdout.close()
def logger():
    logger = logging.getLogger('error_testing')
    hdlr = logging.FileHandler('error.log')
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    logger.setLevel(logging.WARNING)
    logger.error('We have a problem')
    logger.debug('debugging')
    logger.info('some info')
logger()
proc = subprocess.Popen(['FastTree -nt test.fasta'], bufsize=512, stdin = None, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True) 
write_to_stderr_log(proc)
write_to_stdout_log(proc)
Is this the best way to do this. If I have more than one process, I guess its going to re-write the log files, so that could be a problem. Appreciate some advice here. Thanks
 
    