Last active
June 4, 2018 13:01
-
-
Save wwex/93594f088e33720fe8559106bd42cd79 to your computer and use it in GitHub Desktop.
[PyMemos - Exception, traceback, logs] #python #memo #exception #traceback #log
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 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') |
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 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