# redirect print statements to a log file
# Python v3.x

import arcpy, sys, os, traceback, datetime

CURDATE = datetime.date.today()

outpath = "c:\\temp"
logfile = os.path.join(outpath, 'log' + str(CURDATE) + '.txt')

if arcpy.Exists(logfile):
    arcpy.Delete_management(logfile)

                       

with open(logfile, 'a') as log:

    print ('this text printed to shell')
    print ('this is text being redirected to a log text file', file=log)

log.close()
