Created
November 29, 2011 16:36
-
-
Save kzar/1405434 to your computer and use it in GitHub Desktop.
Quick (untested) example of logging standard out and error to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| def log(s, file_name): | |
| with open(file_name, "a") as log_file: | |
| log_file.write(s) | |
| def LogWriter: | |
| def write(self, s): | |
| log(s, "path/to/logfile") | |
| sys.stdout = sys.stderr = LogWriter() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Again untested, modified from http://wiki.python.org/moin/HandlingExceptions | |
| import sys | |
| try: | |
| something_risky() | |
| except: | |
| print repr(sys.exc_info()[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment