Django support for FirePython import logging import firepython import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Django support for FirePython
import logging
import firepython
import threading
class FirePythonDjango(object):
"""
Django middleware to enable FirePython logging.
To use add 'firepython.django.FirePythonDjango' to your MIDDLEWARE_CLASSES
setting.
"""
def __init__(self):
self.local = threading.local()
self.local.handler = firepython.FirePythonLogHandler()
self.local.root = logging.getLogger()
def process_request(self, request):
self.local.root.addHandler(self.local.handler)
self.local.root.setLevel(logging.DEBUG)
def process_response(self, request, response):
self.local.root.removeHandler(self.local.handler)
self.local.handler.flush(response.__setitem__)
return response