Skip to content

Commit 8213abc

Browse files
authored
Merge pull request #44 from DaleSeo/remove-global-logging
Stoping Using Root Logger with One-off Logging Setup
2 parents 1e6df92 + 4de0ad0 commit 8213abc

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

python_graphql_client/graphql_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
import requests
88
import websockets
99

10-
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(message)s")
11-
1210

1311
class GraphqlClient:
1412
"""Class which represents the interface to make graphQL requests through."""
1513

1614
def __init__(self, endpoint: str, headers: dict = {}, **kwargs: Any):
1715
"""Insantiate the client."""
16+
self.logger = logging.getLogger(__name__)
1817
self.endpoint = endpoint
1918
self.headers = headers
2019
self.options = kwargs
@@ -106,8 +105,8 @@ async def subscribe(
106105
async for response_message in websocket:
107106
response_body = json.loads(response_message)
108107
if response_body["type"] == "connection_ack":
109-
logging.info("the server accepted the connection")
108+
self.logger.info("the server accepted the connection")
110109
elif response_body["type"] == "ka":
111-
logging.info("the server sent a keep alive message")
110+
self.logger.info("the server sent a keep alive message")
112111
else:
113112
handle(response_body["payload"])

tests/test_graphql_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ async def test_subscribe(self, mock_connect):
269269
]
270270
)
271271

272-
@patch("logging.info")
272+
@patch("logging.getLogger")
273273
@patch("websockets.connect")
274-
async def test_does_not_crash_with_keep_alive(self, mock_connect, mock_info):
274+
async def test_does_not_crash_with_keep_alive(self, mock_connect, mock_get_logger):
275275
"""Subsribe a GraphQL subscription."""
276276
mock_websocket = mock_connect.return_value.__aenter__.return_value
277277
mock_websocket.send = AsyncMock()
@@ -288,7 +288,9 @@ async def test_does_not_crash_with_keep_alive(self, mock_connect, mock_info):
288288

289289
await client.subscribe(query=query, handle=MagicMock())
290290

291-
mock_info.assert_has_calls([call("the server sent a keep alive message")])
291+
mock_get_logger.return_value.info.assert_has_calls(
292+
[call("the server sent a keep alive message")]
293+
)
292294

293295
@patch("websockets.connect")
294296
async def test_headers_passed_to_websocket_connect(self, mock_connect):

0 commit comments

Comments
 (0)