Apologies if this has been answered before.
I am trying to redirect my console output to a "log" file that includes any error messages. Currently I am able to send my print statements to a file using
sys.stdout = open(r'mydir\Log.txt', 'w')
My question is how do I add any error messages that may come up during my code? My script runs overnight and I am planning to have an email sent to myself with this file detailing where the (if any) error occurred, while also keeping the print statements.
Thank you!