import ftplib
import urllib2
import os
import logging
logger = logging.getLogger(\'ftpuploader\')
hdlr = logging.FileHandler(\'ftplog.log\')
formatter = logging.Form
Using str(e) or repr(e) to represent the exception, you won't get the actual stack trace, so it is not helpful to find where the exception is.
After reading other answers and the logging package doc, the following two ways works great to print the actual stack trace for easier debugging:
logger.debug() with parameter exc_infotry:
# my code
except SomeError as e:
logger.debug(e, exc_info=True)
logger.exception()or we can directly use logger.exception() to print the exception.
try:
# my code
except SomeError as e:
logger.exception(e)