Elffuss BraidHub

kikocis/java-driver public

Log more connection details at trace and debug levels (JAVA-436).
Changeset4625fd285b2c72e237513776f6f1251a0c04a1a02a8d01f86831419de2274341
Authorolim7t <omichallat+github@gmail.com> · 2014-09-01 18:41 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-09-01 18:43 +02:00
Parents26add0c6583f

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -11,6 +11,7 @@
1111 - [bug] Do not use a host when no rpc_address found for it (JAVA-428)
1212 - [improvement] Add ResultSet.wasApplied() for conditional queries (JAVA-358)
1313 - [bug] Fix negative HostConnectionPool open count (JAVA-349)
14+- [improvement] Log more connection details at trace and debug levels (JAVA-436)
1415
1516 2.0.5:
1617 ------
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +16 −16
@@ -102,16 +102,16 @@
102102 if (!future.isSuccess())
103103 {
104104 if (logger.isDebugEnabled())
105- logger.debug(String.format("[%s] Error connecting to %s%s", name, address, extractMessage(future.getCause())));
105+ logger.debug(String.format("%s Error connecting to %s%s", this, address, extractMessage(future.getCause())));
106106 throw defunct(new TransportException(address, "Cannot connect", future.getCause()));
107107 }
108108 } finally {
109109 writer.decrementAndGet();
110110 }
111111
112- logger.trace("[{}] Connection opened successfully", name);
112+ logger.trace("{} Connection opened successfully", this);
113113 initializeTransport(protocolVersion, factory.manager.metadata.clusterName);
114- logger.debug("[{}] Transport initialized and ready", name);
114+ logger.debug("{} Transport initialized and ready", this);
115115 isInitialized = true;
116116 }
117117
@@ -194,7 +194,7 @@
194194 private void waitForAuthCompletion(Message.Response authResponse, Authenticator authenticator) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException {
195195 switch (authResponse.type) {
196196 case AUTH_SUCCESS:
197- logger.trace("Authentication complete");
197+ logger.trace("{} Authentication complete", this);
198198 authenticator.onAuthenticationSuccess(((Responses.AuthSuccess)authResponse).token);
199199 break;
200200 case AUTH_CHALLENGE:
@@ -202,11 +202,11 @@
202202 if (responseToServer == null) {
203203 // If we generate a null response, then authentication has completed, return without
204204 // sending a further response back to the server.
205- logger.trace("Authentication complete (No response to server)");
205+ logger.trace("{} Authentication complete (No response to server)", this);
206206 return;
207207 } else {
208208 // Otherwise, send the challenge response back to the server
209- logger.trace("Sending Auth response to challenge");
209+ logger.trace("{} Sending Auth response to challenge", this);
210210 waitForAuthCompletion(write(new Requests.AuthResponse(responseToServer)).get(), authenticator);
211211 }
212212 break;
@@ -289,7 +289,7 @@
289289 return;
290290
291291 try {
292- logger.trace("[{}] Setting keyspace {}", name, keyspace);
292+ logger.trace("{} Setting keyspace {}", this, keyspace);
293293 long timeout = factory.getConnectTimeoutMillis();
294294 // Note: we quote the keyspace below, because the name is the one coming from Cassandra, so it's in the right case already
295295 Future future = write(new Requests.Query("USE \"" + keyspace + '"'));
@@ -357,7 +357,7 @@
357357 throw new ConnectionException(address, "Connection has been closed");
358358 }
359359
360- logger.trace("[{}] writing request {}", name, request);
360+ logger.trace("{} writing request {}", this, request);
361361 writer.incrementAndGet();
362362 channel.write(request).addListener(writeHandler(request, handler));
363363 return handler;
@@ -371,7 +371,7 @@
371371 writer.decrementAndGet();
372372
373373 if (!writeFuture.isSuccess()) {
374- logger.debug("[{}] Error writing request {}", name, request);
374+ logger.debug("{} Error writing request {}", Connection.this, request);
375375 // Remove this handler from the dispatcher so it don't get notified of the error
376376 // twice (we will fail that method already)
377377 dispatcher.removeHandler(handler.streamId, true);
@@ -384,7 +384,7 @@
384384 }
385385 handler.callback.onException(Connection.this, defunct(ce), System.nanoTime() - handler.startTime);
386386 } else {
387- logger.trace("[{}] request sent successfully", name);
387+ logger.trace("{} request sent successfully", Connection.this);
388388 }
389389 }
390390 };
@@ -413,7 +413,7 @@
413413 return closeFuture.get();
414414 }
415415
416- logger.debug("[{}] closing connection", name);
416+ logger.debug("{} closing connection", this);
417417
418418 boolean terminated = terminate(false, false);
419419 if (!terminated)
@@ -610,13 +610,13 @@
610610 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
611611 if (!(e.getMessage() instanceof Message.Response)) {
612612 String msg = asDebugString(e.getMessage());
613- logger.error("[{}] Received unexpected message: {}", name, msg);
613+ logger.error("{} Received unexpected message: {}", Connection.this, msg);
614614 defunct(new TransportException(address, "Unexpected message received: " + msg));
615615 } else {
616616 Message.Response response = (Message.Response)e.getMessage();
617617 int streamId = response.getStreamId();
618618
619- logger.trace("[{}] received: {}", name, e.getMessage());
619+ logger.trace("{} received: {}", Connection.this, e.getMessage());
620620
621621 if (streamId < 0) {
622622 factory.defaultHandler.handle(response);
@@ -637,8 +637,8 @@
637637 */
638638 streamIdHandler.unmark(streamId);
639639 if (logger.isDebugEnabled())
640- logger.debug("[{}] Response received on stream {} but no handler set anymore (either the request has "
641- + "timed out or it was closed due to another error). Received message is {}", name, streamId, asDebugString(response));
640+ logger.debug("{} Response received on stream {} but no handler set anymore (either the request has "
641+ + "timed out or it was closed due to another error). Received message is {}", Connection.this, streamId, asDebugString(response));
642642 return;
643643 }
644644 handler.cancelTimeout();
@@ -666,7 +666,7 @@
666666 @Override
667667 public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
668668 if (logger.isDebugEnabled())
669- logger.debug(String.format("[%s] connection error", name), e.getCause());
669+ logger.debug(String.format("%s connection error", Connection.this), e.getCause());
670670
671671 // Ignore exception while writing, this will be handled by write() directly
672672 if (writer.get() > 0)