aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command/serve.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@tremily.us>2012-08-23 17:26:36 -0400
committerW. Trevor King <wking@tremily.us>2012-08-23 17:31:15 -0400
commit6b04e1f5b80abcc1dffbce0466f34a182a468064 (patch)
tree808b632318e2898b4d49ad29d93819ad7cbb27fb /libbe/command/serve.py
parent831691bd9aa1ea4092f718fa5ce4da1ce96d06db (diff)
downloadbugseverywhere-6b04e1f5b80abcc1dffbce0466f34a182a468064.tar.gz
command:serve: add SilentRequestHandler to avoid double-logging requests.
They were being logged by the request handler, and then logged again by WSGI_Object.log_request. After this patch, requests are only logged when logger.level is at a <= level (e.g. closer to DEBUG) than the WSGI_Object.log_level (usually INFO). For example, in Serve_setup_logging, self.logger.setLevel(logging.INFO) will get request logs printed, but self.logger.setLevel(logging.WARNING) will not.
Diffstat (limited to 'libbe/command/serve.py')
-rw-r--r--libbe/command/serve.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/libbe/command/serve.py b/libbe/command/serve.py
index 09ff0ff..3bfac0c 100644
--- a/libbe/command/serve.py
+++ b/libbe/command/serve.py
@@ -203,7 +203,7 @@ class WSGI_Object (object):
return [message]
def log_request(self, environ, status='-1 OK', bytes=-1):
- if self.logger == None:
+ if self.logger is None or self.logger.level > self.log_level:
return
req_uri = urllib.quote(environ.get('SCRIPT_NAME', '')
+ environ.get('PATH_INFO', ''))
@@ -744,6 +744,11 @@ class ServerApp (WSGI_AppObject):
libbe.util.subproc.invoke(self.notify, stdin=message, shell=True)
+class SilentRequestHandler (wsgiref.simple_server.WSGIRequestHandler):
+ def log_message(self, format, *args):
+ pass
+
+
class Serve (libbe.command.Command):
"""Serve bug directory storage over HTTP.
@@ -848,7 +853,8 @@ class Serve (libbe.command.Command):
else:
details['protocol'] = 'HTTP'
server = wsgiref.simple_server.make_server(
- params['host'], params['port'], app)
+ params['host'], params['port'], app,
+ handler_class=SilentRequestHandler)
details['socket-name'] = server.socket.getsockname()[0]
return (server, details)