From 3a07a87c88b27c5e7e06ee7d67cd6095272e9159 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 12 Aug 2020 14:37:32 -0700 Subject: Don't log noisy thumbnail and avatar requests in the console --- server.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index ae4dcda..072ed22 100644 --- a/server.py +++ b/server.py @@ -17,6 +17,7 @@ import socket import socks, sockshandler import subprocess import re +import sys @@ -122,12 +123,21 @@ def site_dispatch(env, start_response): return - +class FilteredRequestLog: + '''Don't log noisy thumbnail and avatar requests''' + filter_re = re.compile(r'"GET /https://(i\.ytimg\.com/|www.youtube\.com/data/subscription_thumbnails/|yt3.ggpht.com/).*" 200') + def __init__(self): + pass + def write(self, s): + if not self.filter_re.search(s): + sys.stderr.write(s) if settings.allow_foreign_addresses: - server = WSGIServer(('0.0.0.0', settings.port_number), site_dispatch) + server = WSGIServer(('0.0.0.0', settings.port_number), site_dispatch, + log=FilteredRequestLog()) else: - server = WSGIServer(('127.0.0.1', settings.port_number), site_dispatch) + server = WSGIServer(('127.0.0.1', settings.port_number), site_dispatch, + log=FilteredRequestLog()) print('Started httpserver on port ' , settings.port_number) server.serve_forever() -- cgit v1.2.3