Skip to content

Commit

Permalink
Merge pull request #964 from ably/error-log-stack-traces
Browse files Browse the repository at this point in the history
Error log stack traces
  • Loading branch information
AndyTWF authored Jul 17, 2023
2 parents 28ffd6b + 25da9a9 commit a38b026
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/src/main/java/io/ably/lib/http/HttpCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,14 @@ <T> T httpExecute(HttpURLConnection conn, String method, Param[] headers, Reques
byte[] body = null;
if(requestBody != null) {
body = prepareRequestBody(requestBody, conn);
// Check the logging level to avoid performance hit associated with building the message
if (Log.level <= Log.VERBOSE)
Log.v(TAG, System.lineSeparator() + new String(body));
}

/* log raw request details */
Map<String, List<String>> requestProperties = conn.getRequestProperties();
// Check the logging level to avoid performance hit associated with building the message
if (Log.level <= Log.VERBOSE) {
Log.v(TAG, "HTTP request: " + conn.getURL() + " " + method);
if (credentialsIncluded)
Expand Down Expand Up @@ -251,7 +253,6 @@ <T> T httpExecute(HttpURLConnection conn, String method, Param[] headers, Reques
rawHttpListener.onRawHttpResponse(id, method, response);
}
} catch(IOException ioe) {
ioe.printStackTrace();
if(rawHttpListener != null) {
rawHttpListener.onRawHttpException(id, method, ioe);
}
Expand Down Expand Up @@ -400,6 +401,7 @@ private Response readResponse(HttpURLConnection connection) throws IOException {
for (Map.Entry<String, List<String>> entry : caseSensitiveHeaders.entrySet()) {
if (entry.getKey() != null) {
response.headers.put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue());
// Check the logging level to avoid performance hit associated with building the message
if (Log.level <= Log.VERBOSE)
for (String val : entry.getValue())
Log.v(TAG, entry.getKey() + ": " + val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ public void onMessage(ITransport transport, ProtocolMessage message) throws Ably
if (transport != null && this.transport != transport) {
return;
}
// Check the logging level to avoid performance hit associated with building the message
if (Log.level <= Log.VERBOSE) {
Log.v(TAG, "onMessage() (transport = " + transport + "): " + message.action + ": " + new String(ProtocolSerializer.writeJSON(message)));
}
Expand Down Expand Up @@ -1591,6 +1592,7 @@ protected boolean checkConnectivity() {
try {
return HttpHelpers.getUrlString(ably.httpCore, INTERNET_CHECK_URL).contains(INTERNET_CHECK_OK);
} catch(AblyException e) {
Log.d(TAG, "Exception whilst checking connectivity", e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ public void send(ProtocolMessage msg) throws AblyException {
try {
if(channelBinaryMode) {
byte[] encodedMsg = ProtocolSerializer.writeMsgpack(msg);

// Check the logging level to avoid performance hit associated with building the message
if (Log.level <= Log.VERBOSE) {
ProtocolMessage decodedMsg = ProtocolSerializer.readMsgpack(encodedMsg);
Log.v(TAG, "send(): " + decodedMsg.action + ": " + new String(ProtocolSerializer.writeJSON(decodedMsg)));
}
wsConnection.send(encodedMsg);
} else {
// Check the logging level to avoid performance hit associated with building the message
if (Log.level <= Log.VERBOSE)
Log.v(TAG, "send(): " + new String(ProtocolSerializer.writeJSON(msg)));
wsConnection.send(ProtocolSerializer.writeJSON(msg));
Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/java/io/ably/lib/types/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static Message[] fromEncodedArray(JsonArray messageArray, ChannelOptions
}
return messages;
} catch(Exception e) {
e.printStackTrace();
Log.e(Message.class.getName(), e.getMessage(), e);
throw MessageDecodeException.fromDescription(e.getMessage());
}
}
Expand All @@ -295,7 +295,7 @@ public static Message[] fromEncodedArray(String messagesArray, ChannelOptions ch
JsonArray jsonArray = Serialisation.gson.fromJson(messagesArray, JsonArray.class);
return fromEncodedArray(jsonArray, channelOptions);
} catch(Exception e) {
e.printStackTrace();
Log.e(Message.class.getName(), e.getMessage(), e);
throw MessageDecodeException.fromDescription(e.getMessage());
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ public Message deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo
try {
message.read((JsonObject)json);
} catch (MessageDecodeException e) {
e.printStackTrace();
Log.e(Message.class.getName(), e.getMessage(), e);
throw new JsonParseException("Failed to deserialize Message from JSON.", e);
}
return message;
Expand Down

0 comments on commit a38b026

Please sign in to comment.