Skip to content

Commit

Permalink
logging fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
liampauling committed Oct 10, 2020
1 parent 2efaf35 commit 32a5f6c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions betfairlightweight/streaming/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, max_latency: Optional[float] = 0.5):
self.connections_available = None # connection throttling

def register_stream(self, unique_id: int, operation: str) -> None:
logger.info("Register: %s %s" % (operation, unique_id))
logger.info("[Register: %s]: %s" % (unique_id, operation))
if self.stream is not None:
logger.warning(
"[Listener: %s]: stream already registered, replacing data" % unique_id
Expand Down Expand Up @@ -137,7 +137,7 @@ def _on_connection(self, data: dict, unique_id: int) -> None:
unique_id = self.stream_unique_id
self.connection_id = data.get("connectionId")
logger.info(
"[Connect: %s]: connection_id: %s" % (unique_id, self.connection_id)
"[%s: %s]: connection_id: %s" % (self.stream, unique_id, self.connection_id)
)

def _on_status(self, data: dict, unique_id: int) -> None:
Expand All @@ -150,14 +150,14 @@ def _on_status(self, data: dict, unique_id: int) -> None:
if connections_available:
self.connections_available = data.get("connectionsAvailable")
logger.info(
"[Subscription: %s]: %s (%s connections available)"
% (unique_id, status_code, self.connections_available)
"[%s: %s]: %s (%s connections available)"
% (self.stream, unique_id, status_code, self.connections_available)
)

def _on_change_message(self, data: dict, unique_id: int) -> None:
change_type = data.get("ct", "UPDATE")

logger.debug("[Subscription: %s]: %s: %s" % (unique_id, change_type, data))
logger.debug("[%s: %s]: %s: %s" % (self.stream, unique_id, change_type, data))

if change_type == "SUB_IMAGE":
self.stream.on_subscribe(data)
Expand All @@ -177,12 +177,19 @@ def _error_handler(self, data: dict, unique_id: int) -> Optional[bool]:
"""
if data.get("statusCode") == "FAILURE":
logger.error(
"[Subscription: %s] %s: %s"
% (unique_id, data.get("errorCode"), data.get("errorMessage"))
"[%s: %s]: %s: %s"
% (
self.stream,
unique_id,
data.get("errorCode"),
data.get("errorMessage"),
)
)
if data.get("connectionClosed"):
return True
if self.status:
# Clients shouldn't disconnect if status 503 is returned; when the stream
# recovers updates will be sent containing the latest data
logger.warning("[Subscription: %s] status: %s" % (unique_id, self.status))
logger.warning(
"[%s: %s]: status: %s" % (self.stream, unique_id, self.status)
)

0 comments on commit 32a5f6c

Please sign in to comment.