Django Unhandled Exception

django, python

Solution

Maybe you can use this snippet, this will log exceptions in apache's log:

`utils.py`:

def log_traceback(exception, args):
    import sys, traceback, logging
    exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
    logging.debug(exception)
    logging.debug(args)
    for tb in traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback):
        logging.debug(tb)

`site_logging.py`:

import logging
import sys

logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

Put it in your `settings.py` :

import site_logging

And in your code:

from where.is.your.utils import log_traceback
try:
   `do something`
except Exception, args:
    log_traceback(Exception, args)

Problem

It is running under DEBUG = True mode. Sometimes it can throw out an error message with traceback information when encounter an error but sometimes it just display the following lines: ``` Unhandled Exception An unhandled exception was thrown by the application. ``` I have to switch to development server to see detail message. How can I make it always display traceback message when an error is encountered?

Original source