import logging import firepython import threading class FirePythonWSGI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import logging
import firepython
import threading
class FirePythonWSGI(object):
"""
WSGI middleware to enable FirePython logging.
"""
def __init__(self, app):
self.local = threading.local()
self.local.app = app
self.local.handler = firepython.FirePythonLogHandler()
self.local.root = logging.getLogger()
self.local.root.addHandler(self.handler)
self.local.root.setLevel(logging.DEBUG)
def __call__(self, environ, start_response):
def fake_start_response(status, headers, exc_info=None):
def cb_add_header(name, value):
headers.append((name, value))
self.local.handler.flush(cb_add_header)
start_response(status, headers, exc_info=None)
return self.local.app(environ, fake_start_response)