I have logging function as follows.
logging.basicConfig( filename = fileName, format = \"%(levelname) -10s %(asctime)s %(message)s\", level = logging
Use the traceback module.
logging.error(traceback.format_exc())