Skip to content

Instantly share code, notes, and snippets.

@wwex
Last active June 4, 2018 13:01
Show Gist options
  • Save wwex/93594f088e33720fe8559106bd42cd79 to your computer and use it in GitHub Desktop.
Save wwex/93594f088e33720fe8559106bd42cd79 to your computer and use it in GitHub Desktop.
[PyMemos - Exception, traceback, logs] #python #memo #exception #traceback #log
import logging
logging.basicConfig(filename='myProgLog.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
# logging.disable(logging.CRITICAL)
logging.debug('Start of program')
def factorial(n):
logging.debug('Start of factorial(%s)' %(n))
total = 1
if not ((n == 0) or (n == 1)):
for i in range(1, n+1):
total *= i
logging.debug('Return value is %s' %(total))
logging.debug('Return value is %s' %(total))
return total
logging.debug('End of porogram')
import traceback
try:
raise Exception('This is the error message')
except:
errorFile = open('error_log.txt', 'a')
errorFile.write(traceback.format_exc())
errorFile.close()
print('The traceback info was written to error_log.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment