Newb python question. I've been reading up on tee() and different ways of splitting output. But i cant find a good example for splitting output to the terminal and to a log file. I've been playing around with some options and this is what I have so far:
def logname():
env.warn_only = True
timestamp = time.strftime("%d_%b_%Y")
return "%s_%s" % (env.host_string, timestamp)
sys.stdout = open('/home/path/to/my/log/directory/%s' % logname(), 'w')
The above will log to a file with the host name_datestamp but won't display anything on screen. Then when I want to stop logging i do:
sys.stdout = sys.__stdout__
How can I log to my file with the definiton above and display to the terminal at the same time? Am I on the right path with tee()?