Skip to content

use hostnames and ports in warnings #572

Open
wants to merge 3 commits into from
View
23 tornado/iostream.py 100644 → 100755
@@ -89,6 +89,7 @@ def __init__(self, socket, io_loop=None, max_buffer_size=104857600,
self.max_buffer_size = max_buffer_size
self.read_chunk_size = read_chunk_size
self.error = None
+ self.address = (None, 0)
self._read_buffer = collections.deque()
self._write_buffer = collections.deque()
self._read_buffer_size = 0
@@ -123,6 +124,7 @@ def connect(self, address, callback=None):
"""
self._connecting = True
try:
+ self.address = address
self.socket.connect(address)
except socket.error, e:
# In non-blocking mode we expect connect() to raise an
@@ -133,7 +135,8 @@ def connect(self, address, callback=None):
# localhost, so handle them the same way as an error
# reported later in _handle_connect.
if e.args[0] not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
- logging.warning("Connect error on fd %d: %s",
+ logging.warning("Connect error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), e)
self.close()
return
@@ -421,7 +424,8 @@ def _read_to_buffer(self):
chunk = self._read_from_socket()
except socket.error, e:
# ssl.SSLError is a subclass of socket.error
- logging.warning("Read error on %d: %s",
+ logging.warning("Read error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), e)
self.close()
raise
@@ -503,7 +507,8 @@ def _handle_connect(self):
# an error state before the socket becomes writable, so
# in that case a connection failure would be handled by the
# error path in _handle_events instead of here.
- logging.warning("Connect error on fd %d: %s",
+ logging.warning("Connect error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), errno.errorcode[err])
self.close()
return
@@ -543,7 +548,8 @@ def _handle_write(self):
self._write_buffer_frozen = True
break
else:
- logging.warning("Write error on %d: %s",
+ logging.warning("Write error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), e)
self.close()
return
@@ -650,12 +656,9 @@ def _do_ssl_handshake(self):
ssl.SSL_ERROR_ZERO_RETURN):
return self.close()
elif err.args[0] == ssl.SSL_ERROR_SSL:
- try:
- peer = self.socket.getpeername()
- except:
- peer = '(not connected)'
- logging.warning("SSL Error on %d %s: %s",
- self.socket.fileno(), peer, err)
+ logging.warning("SSL Error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
+ self.socket.fileno(), err)
return self.close()
raise
except socket.error, err:
View
6 tornado/web.py
@@ -1449,8 +1449,10 @@ def log_request(self, handler):
else:
log_method = logging.error
request_time = 1000.0 * handler.request.request_time()
- log_method("%d %s %.2fms", handler.get_status(),
- handler._request_summary(), request_time)
+ error_msg = "%d %s" % (handler.get_status(),
+ handler._request_summary())
+ error_msg = error_msg.replace('%', '%%')
+ log_method(error_msg + " %.2fms", request_time)
class HTTPError(Exception):
Something went wrong with that request. Please try again.