url logging

log the actual bind url (Server.bind_url),
rather than the connect url (Server.url),
which converts all-interfaces IPs to 'localhost'
This commit is contained in:
Min RK
2015-03-14 14:28:36 -06:00
parent 40ae3a5821
commit 5529774c1d
4 changed files with 30 additions and 8 deletions

View File

@@ -75,12 +75,16 @@ class Server(Base):
@property
def host(self):
ip = self.ip
if ip in {'', '0.0.0.0'}:
# when listening on all interfaces, connect to localhost
ip = 'localhost'
return "{proto}://{ip}:{port}".format(
proto=self.proto,
ip=self.ip or 'localhost',
ip=ip,
port=self.port,
)
@property
def url(self):
return "{host}{uri}".format(
@@ -88,6 +92,17 @@ class Server(Base):
uri=self.base_url,
)
@property
def bind_url(self):
"""representation of URL used for binding
Never used in APIs, only logging,
since it can be non-connectable value, such as '', meaning all interfaces.
"""
if self.ip in {'', '0.0.0.0'}:
return self.url.replace('localhost', self.ip or '*', 1)
return self.url
@gen.coroutine
def wait_up(self, timeout=10, http=False):
"""Wait for this server to come up"""