diff --git a/setup.py b/setup.py index 7734d50..ad95a1e 100755 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/warcprox/__init__.py b/warcprox/__init__.py index 2bf0f02..fade9a0 100644 --- a/warcprox/__init__.py +++ b/warcprox/__init__.py @@ -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 diff --git a/warcprox/mitmproxy.py b/warcprox/mitmproxy.py index e79746e..951eb0e 100644 --- a/warcprox/mitmproxy.py +++ b/warcprox/mitmproxy.py @@ -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)