less debug output, only log http requests if enabled

This commit is contained in:
j 2015-11-29 17:07:01 +01:00
parent 444c357e54
commit 3182d4eaeb
6 changed files with 26 additions and 12 deletions

View file

@ -34,18 +34,15 @@ def can_connect(data):
url = 'https://{host}:{port}'.format(**data)
opener.addheaders = list(zip(headers.keys(), headers.values()))
opener.timeout = 1
logger.debug('try connection %s', url)
r = opener.open(url)
version = r.headers.get('X-Node-Protocol', None)
if version != settings.NODE_PROTOCOL:
logger.debug('version does not match local: %s remote %s', settings.NODE_PROTOCOL, version)
return False
c = r.read()
logger.debug('can connect to local node')
return True
except:
logger.debug('can_connect failed', exc_info=1)
pass
logger.debug('failed to connect to local node %s', data, exc_info=1)
return False
class LocalNodesBase(Thread):
@ -175,7 +172,7 @@ class LocalNodes4(LocalNodesBase):
def send(self):
packet = self.get_packet()
if packet:
logger.debug('send4 %s', packet)
#logger.debug('send4 %s', packet)
sockaddr = (self._BROADCAST, self._PORT)
s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt (socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, self._TTL)
@ -205,7 +202,7 @@ class LocalNodes6(LocalNodesBase):
def send(self):
packet = self.get_packet()
if packet:
logger.debug('send6 %s', packet)
#logger.debug('send6 %s', packet)
ttl = struct.pack('@i', self._TTL)
address = self._BROADCAST + get_interface()
addrs = socket.getaddrinfo(address, self._PORT, socket.AF_INET6, socket.SOCK_DGRAM)

View file

@ -98,6 +98,11 @@ class Handler(http.server.SimpleHTTPRequestHandler):
def version_string(self):
return settings.USER_AGENT
def log_message(self, format, *args):
if settings.DEBUG_HTTP:
logger.debug("%s - - [%s] %s\n", self.address_string(),
self.log_date_time_string(), format%args)
def do_HEAD(self):
return self.do_GET()
@ -124,7 +129,6 @@ class Handler(http.server.SimpleHTTPRequestHandler):
self.send_header('X-Node-Protocol', settings.NODE_PROTOCOL)
self.send_header('Content-Length', str(os.path.getsize(path)))
self.end_headers()
logger.debug('GET file %s', id)
with open(path, 'rb') as f:
while 1:
data = f.read(16384)

View file

@ -447,7 +447,6 @@ def publish_node():
def update_online():
online = state.tor and state.tor.is_online()
logger.debug('update online %s', online)
if online != state.online:
state.online = online
trigger_event('status', {

View file

@ -42,18 +42,31 @@ class MainHandler(OMLHandler):
self.set_header('Content-Length', str(len(content)))
self.write(content)
def log_request(handler):
if settings.DEBUG_HTTP:
if handler.get_status() < 400:
log_method = logger.info
elif handler.get_status() < 500:
log_method = logger.warning
else:
log_method = logger.error
request_time = 1000.0 * handler.request.request_time()
log_method("%d %s %.2fms", handler.get_status(),
handler._request_summary(), request_time)
def run():
setup.create_db()
PID = sys.argv[2] if len(sys.argv) > 2 else None
log_format='%(asctime)s:%(levelname)s:%(name)s:%(message)s'
if not PID:
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG, format=log_format)
else:
logging.basicConfig(level=logging.DEBUG,
filename=settings.log_path, filemode='w',
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s')
format=log_format)
options = {
'debug': False,
'log_function': log_request,
'gzip': True
}

View file

@ -80,3 +80,5 @@ VERSION="%s.%s" % (NODE_PROTOCOL, MINOR_VERSION)
USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
DEBUG_HTTP = server.get('debug_http', False)

View file

@ -81,9 +81,8 @@ class TorHTTPSConnection(http.client.HTTPSConnection):
def _check_service_id(self, cert):
service_id = get_service_id(cert=cert)
logger.debug('ssl service_id: %s (match: %s)', service_id, service_id == self._service_id)
if service_id != self._service_id:
logger.debug('expected service_id: %s', self._service_id)
logger.debug('service_id mismatch: %s expected: %s', service_id, self._service_id)
return service_id == self._service_id
def connect(self):