better logging

This commit is contained in:
j 2016-04-05 01:28:55 +02:00
parent c7ce20a3b9
commit 6eff308468
2 changed files with 9 additions and 10 deletions

View file

@ -245,7 +245,7 @@ class Handler(http.server.SimpleHTTPRequestHandler):
}
self.write_response(response_status, content)
return
logger.debug('NODE action %s %s (%s)', action, args, user_id)
logger.debug('%s requests %s%s', user_id, action, args)
if action == 'ping':
content = {
'status': 'ok'
@ -267,9 +267,11 @@ class Handler(http.server.SimpleHTTPRequestHandler):
self.send_header('Content-Type', 'application/json')
content = json.dumps(content, ensure_ascii=False).encode('utf-8')
content = self.gzip_data(content)
self.send_header('Content-Length', str(len(content)))
content_length = len(content)
self.send_header('Content-Length', str(content_length))
self.end_headers()
self.wfile.write(content)
logger.debug('%s bytes response', content_length)
def chunk_size(self, content_length):
return min(16*1024, content_length)

View file

@ -71,13 +71,12 @@ class Node(Thread):
@property
def url(self):
url = None
if self.local:
if ':' in self.local:
url = 'https://[%s]:%s' % (self.local, self.port)
else:
url = 'https://%s:%s' % (self.local, self.port)
elif len(self.user_id) == 16:
else:
url = 'https://%s.onion:9851' % self.user_id
return url
@ -110,14 +109,12 @@ class Node(Thread):
return None
def request(self, action, *args):
logger.debug('request[%s] %s%s', self.user_id, action, args)
self.resolve()
url = self.url
if not url:
logger.debug('unable to find host %s', self.user_id)
self.online = False
return None
#logger.debug('url=%s', url)
if self.local:
logger.debug('request:%s(%s:%s): %s%s', self.user_id, self.local, self.port, action, list(args))
else:
logger.debug('request:%s: %s%s', self.user_id, action, list(args))
content = json.dumps([action, args]).encode()
headers = {
'User-Agent': settings.USER_AGENT,