Log each rpc msg in snippet client for better debugging. (#473)
* Log each rpc msg in snippet client for better debugging.
diff --git a/mobly/controllers/android_device_lib/jsonrpc_client_base.py b/mobly/controllers/android_device_lib/jsonrpc_client_base.py
index 279360d..498434d 100644
--- a/mobly/controllers/android_device_lib/jsonrpc_client_base.py
+++ b/mobly/controllers/android_device_lib/jsonrpc_client_base.py
@@ -19,7 +19,7 @@
Request:
{
- "id": <monotonically increasing integer containing the ID of
+ "id": <monotonically increasing integer containing the ID of
this request>
"method": <string containing the name of the method to execute>
"params": <JSON array containing the arguments to the method>
@@ -239,6 +239,7 @@
try:
self._client.write(msg.encode("utf8") + b'\n')
self._client.flush()
+ self.log.debug('Snippet sent %s.', msg)
except socket.error as e:
raise Error(
self._ad,
@@ -255,7 +256,9 @@
Error: a socket error occurred during the read.
"""
try:
- return self._client.readline()
+ response = self._client.readline()
+ self.log.debug('Snippet received: %s', response)
+ return response
except socket.error as e:
raise Error(
self._ad,
@@ -299,7 +302,7 @@
if not response:
raise ProtocolError(self._ad,
ProtocolError.NO_RESPONSE_FROM_SERVER)
- result = json.loads(str(response, encoding="utf8"))
+ result = json.loads(str(response, encoding='utf8'))
if result['error']:
raise ApiError(self._ad, result['error'])
if result['id'] != apiid: