Hello list. I have a question. To my could be really helpful write a
"log file" with the errors, to revise at the next day if something
happen. For the moment I have this, a middleware class:
----------------------------------------------------------------------------------------------
from django.conf import settings
import traceback
import sys
import logging

class TestMiddleware:
    def getUser(self, request):
        ...

    def process_exception(self, request, exception):
        try:
            tb = sys.exc_info()[2]
            ubication = traceback.extract_tb(tb).pop()
            message = u'Type: %s\nValor: %s\nFile, line, function: %s,
%s, %s\nUser: %s' % (type(exception).__name__,
exception.__unicode__(), ubication[0], ubication[1], ubicacion[2],
self.getUser(request))

            logging.basicConfig(filename = settings.LOG_FILE,
filemode = 'a', format='Nivel: %(levelname)s\nDate-hour: %(asctime)s\n
%(message)s\n', level=logging.ERROR)
            logging.error(message)
        except:
            pass
        return None

----------------------------------------------------------------------------------------------
But something is missing. I only catch exceptions thrown from views. I
can't catch FATAL errors like problems in the connection with the
database. Errors like that don't go to this code.
Somebody have an idea to capture that exceptions, maybe in another
function?

Cheers , Thanks for read and sorry for my bad english.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to