Log print message into a file : Standard Redirect « Development « Python






Log print message into a file

Log print message into a file
import sys

print 'Dive in'
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
print 'This message will be logged instead of displayed'
sys.stdout = saveout
fsock.close()


           
       








Related examples in the same category

1.Link Python system error stream into a file
2.Link Python print stream into a fileLink Python print stream into a file
3.Map string to sys.stout.writeMap string to sys.stout.write
4.Redirects prints to file