Logging Exceptions
Use the logging module with logging.exception() to record errors with full tracebacks in production code.
Use the logging module with logging.exception() to record errors with full tracebacks in production code.
import logging
logging.basicConfig(level=logging.ERROR)
try:
result = 1 / 0
except ZeroDivisionError:
logging.exception("Unexpected error occurred")
logging.exception() automatically includes the traceback.