early trace-level logging of the requestline

This commit is contained in:
Noah Levitt 2017-05-03 18:39:57 -07:00
parent c0e6c219ca
commit 11e11f4e68
3 changed files with 19 additions and 4 deletions

View File

@ -51,7 +51,7 @@ except:
setuptools.setup(
name='warcprox',
version='2.1b1.dev73',
version='2.1b1.dev74',
description='WARC writing MITM HTTP/S proxy',
url='https://github.com/internetarchive/warcprox',
author='Noah Levitt',

View File

@ -92,8 +92,17 @@ class RequestBlockedByRule(Exception):
def __str__(self):
return "%s: %s" % (self.__class__.__name__, self.msg)
# logging level more fine-grained than logging.DEBUG==10
# monkey-patch log level TRACE
TRACE = 5
import logging
def _logging_trace(msg, *args, **kwargs):
logging.root.trace(msg, *args, **kwargs)
def _logger_trace(self, msg, *args, **kwargs):
if self.isEnabledFor(TRACE):
self._log(TRACE, msg, args, **kwargs)
logging.trace = _logging_trace
logging.Logger.trace = _logger_trace
logging.addLevelName(TRACE, 'TRACE')
import warcprox.controller as controller
import warcprox.playback as playback

View File

@ -6,7 +6,7 @@ calling ssl.wrap_socket() on the client connection; connects to remote
configured
Copyright (C) 2012 Cygnos Corporation
Copyright (C) 2013-2016 Internet Archive
Copyright (C) 2013-2017 Internet Archive
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -279,6 +279,9 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
server. Then it calls self.handle_one_request() again to handle the
request intended for the remote server.
'''
self.logger.trace(
'request from %s:%s: %s', self.client_address[0],
self.client_address[1], self.requestline)
self.is_connect = True
try:
self._determine_host_port()
@ -322,6 +325,9 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
return result
def do_COMMAND(self):
self.logger.trace(
'request from %s:%s: %s', self.client_address[0],
self.client_address[1], self.requestline)
if self.is_connect:
self.url = self._construct_tunneled_url()
else:
@ -402,7 +408,7 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
except socket.timeout as e:
self.logger.warn(
"%s proxying %s %s", repr(e), self.command, self.url)
except BaseException as e:
except Exception as e:
self.logger.error(
"%s proxying %s %s", repr(e), self.command, self.url,
exc_info=True)