Skip to content

Instantly share code, notes, and snippets.

@kzar
Created November 29, 2011 16:36
Show Gist options
  • Select an option

  • Save kzar/1405434 to your computer and use it in GitHub Desktop.

Select an option

Save kzar/1405434 to your computer and use it in GitHub Desktop.
Quick (untested) example of logging standard out and error to a file
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()
# 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