Skip to content

Commit 0c7a590

Browse files
committed
chore: fixing logging
Signed-off-by: Caleb Siebach <caleb@indicio.tech>
1 parent 008b503 commit 0c7a590

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

socketdock/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async def status_handler(request: Request):
4343
@api.post("/socket/<connectionid>/send")
4444
async def socket_send(request: Request, connectionid: str):
4545
"""Send a message to a connected socket."""
46-
LOGGER.info("Inbound message for %s", connectionid)
47-
LOGGER.debug("Existing connections: %s", active_connections.keys())
46+
LOGGER.info(f"Inbound message for {connectionid}")
47+
LOGGER.debug(f"Existing connections: {active_connections.keys()}")
4848

4949
if connectionid not in active_connections:
5050
return text("FAIL", status=500)
@@ -60,8 +60,8 @@ async def socket_send(request: Request, connectionid: str):
6060
@api.post("/socket/<connectionid>/disconnect")
6161
async def socket_disconnect(request: Request, connectionid: str):
6262
"""Disconnect a socket."""
63-
LOGGER.info("Disconnect %s", connectionid)
64-
LOGGER.debug("Existing connections: %s", active_connections.keys())
63+
LOGGER.info(f"Disconnect {connectionid}")
64+
LOGGER.debug(f"Existing connections: {active_connections.keys()}")
6565

6666
if connectionid not in active_connections:
6767
return text("FAIL", status=500)
@@ -83,9 +83,9 @@ async def socket_handler(request: Request, websocket: Websocket):
8383
socket_id = websocket.ws_proto.id.hex
8484
active_connections[socket_id] = websocket
8585
lifetime_connections += 1
86-
LOGGER.debug("Existing connections: %s", active_connections.keys())
87-
LOGGER.debug("Added connection: %s", socket_id)
88-
LOGGER.debug("Request headers: %s", dict(request.headers.items()))
86+
LOGGER.debug(f"Existing connections: {active_connections.keys()}")
87+
LOGGER.debug(f"Added connection: {socket_id}")
88+
LOGGER.debug(f"Request headers: {dict(request.headers.items())}")
8989

9090
await backend.socket_connected(
9191
connection_id=socket_id,
@@ -105,5 +105,5 @@ async def socket_handler(request: Request, websocket: Websocket):
105105
# unregister user
106106
if socket_id:
107107
del active_connections[socket_id]
108-
LOGGER.info("Removed connection: %s", socket_id)
108+
LOGGER.info(f"Removed connection: {socket_id}")
109109
await backend.socket_disconnected(socket_id)

socketdock/httpbackend.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ async def socket_connected(
5858

5959
if self._connect_uri:
6060
async with aiohttp.ClientSession() as session:
61-
LOGGER.info("Posting message %s to %s", http_body, self._connect_uri)
61+
LOGGER.info(f"Posting message {http_body} to { self._connect_uri}")
6262
async with session.post(self._connect_uri, json=http_body) as resp:
6363
response = await resp.text()
6464
if resp.status != 200:
65-
LOGGER.error("Error posting message: %s", response)
65+
LOGGER.error(f"Error posting message: {response}")
6666
else:
67-
LOGGER.debug("Response: %s", response)
67+
LOGGER.debug(f"Response: {response}")
6868

6969
async def inbound_socket_message(
7070
self,
@@ -81,25 +81,25 @@ async def inbound_socket_message(
8181
}
8282

8383
async with aiohttp.ClientSession() as session:
84-
LOGGER.info("Posting message %s to %s", http_body, self._message_uri)
84+
LOGGER.info(f"Posting message {http_body} to {self._message_uri}")
8585
async with session.post(self._message_uri, json=http_body) as resp:
8686
response = await resp.text()
8787
if resp.status != 200:
88-
LOGGER.error("Error posting message: %s", response)
88+
LOGGER.error(f"Error posting message: {response}")
8989
else:
90-
LOGGER.debug("Response: %s", response)
90+
LOGGER.debug(f"Response: {response}")
9191

9292
async def socket_disconnected(self, connection_id: str):
9393
"""Handle socket disconnected."""
9494
async with aiohttp.ClientSession() as session:
9595
LOGGER.info(
96-
"Notifying of disconnect: %s %s", self._disconnect_uri, connection_id
96+
f"Notifying of disconnect: {self._disconnect_uri} {connection_id}"
9797
)
9898
async with session.post(
9999
self._disconnect_uri, json={"connection_id": connection_id}
100100
) as resp:
101101
response = await resp.text()
102102
if resp.status != 200:
103-
LOGGER.error("Error posting to disconnect uri: %s", response)
103+
LOGGER.error(f"Error posting to disconnect uri: {response}")
104104
else:
105-
LOGGER.debug("Response: %s", response)
105+
LOGGER.debug(f"Response: {response}")

socketdock/loadlogger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_resource(path: str, encoding: Optional[str] = None):
3636
return io.TextIOWrapper(bstream, encoding=encoding)
3737
return bstream
3838
except IOError:
39-
LOGGER.warning("Resource not found: %s", path)
39+
LOGGER.warning(f"Resource not found: {path}")
4040
return None
4141

4242

socketdock/testbackend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ async def socket_connected(
2525
2626
This test backend doesn't care, but can be useful to clean up state.
2727
"""
28-
LOGGER.debug("Connected to test backend: %s", connection_id)
28+
LOGGER.debug(f"Connected to test backend: {connection_id}")
2929

3030
async def inbound_socket_message(
3131
self,
3232
connection_id: str,
3333
message: Union[str, bytes],
3434
):
3535
"""Receive socket message."""
36-
LOGGER.debug("Recieved message [%s]: %s", connection_id, message)
36+
LOGGER.debug(f"Recieved message [{connection_id}]: {message}")
3737
send_uri = f"{self.base_uri}/socket/{connection_id}/send"
3838
async with aiohttp.ClientSession() as session:
3939
async with session.post(send_uri, data="Hello yourself") as resp:
4040
if not resp.ok:
4141
raise Exception(f"Failed to post to: {send_uri}")
4242
response = await resp.text()
43-
LOGGER.debug("Response: %s", response)
43+
LOGGER.debug(f"Response: {response}")
4444

4545
async def socket_disconnected(self, connection_id: str):
4646
"""Socket disconnected.
4747
4848
This test backend doesn't care, but can be useful to clean up state.
4949
"""
50-
LOGGER.debug("Disconnected from test backend: %s", connection_id)
50+
LOGGER.debug(f"Disconnected from test backend: {connection_id}")

0 commit comments

Comments
 (0)