You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2024/09/05 16:15:17 UTC

(activemq-artemis) branch main updated: ARTEMIS-5034 improve & document OpenWire protocol logging

This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 50c20554d8 ARTEMIS-5034 improve & document OpenWire protocol logging
50c20554d8 is described below

commit 50c20554d8efbc7afc085ae041b9f69a2f3d6726
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Thu Sep 5 10:47:28 2024 -0500

    ARTEMIS-5034 improve & document OpenWire protocol logging
---
 .../core/protocol/openwire/OpenWireConnection.java | 44 +++++++++++-----------
 docs/user-manual/openwire.adoc                     |  8 ++++
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
index 28f7a46662..2ad3913f20 100644
--- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
+++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
@@ -283,13 +283,6 @@ public class OpenWireConnection extends AbstractRemotingConnection implements Se
       LAST_SENT_UPDATER.lazySet(this, System.currentTimeMillis());
    }
 
-   /**
-    * Log packaged into a separate method for performance reasons.
-    */
-   private static void traceBufferReceived(Object connectionID, Command command) {
-      logger.trace("connectionID: {} RECEIVED: {}", connectionID, (command == null ? "NULL" : command));
-   }
-
    @Override
    public void bufferReceived(Object connectionID, ActiveMQBuffer buffer) {
       super.bufferReceived(connectionID, buffer);
@@ -297,10 +290,7 @@ public class OpenWireConnection extends AbstractRemotingConnection implements Se
       try {
          Command command = (Command) inWireFormat.unmarshal(buffer);
 
-         // log the openwire command
-         if (logger.isTraceEnabled()) {
-            traceBufferReceived(connectionID, command);
-         }
+         logCommand(command, true);
 
          final ThresholdActor<Command> localVisibleActor = openWireActor;
          if (localVisibleActor != null) {
@@ -526,21 +516,12 @@ public class OpenWireConnection extends AbstractRemotingConnection implements Se
       return state;
    }
 
-   /**
-    * Log packaged into a separate method for performance reasons.
-    */
-   private static void tracePhysicalSend(Connection transportConnection, Command command) {
-      logger.trace("connectionID: {} SENDING: {}", (transportConnection == null ? "" : transportConnection.getID()), (command == null ? "NULL" : command));
-   }
-
    public void physicalSend(Command command) throws IOException {
       if (this.protocolManager.invokeOutgoing(command, this) != null) {
          return;
       }
 
-      if (logger.isTraceEnabled()) {
-         tracePhysicalSend(transportConnection, command);
-      }
+      logCommand(command, false);
 
       try {
          final ByteSequence bytes = outWireFormat.marshal(command);
@@ -1911,4 +1892,25 @@ public class OpenWireConnection extends AbstractRemotingConnection implements Se
    public CoreMessageObjectPools getCoreMessageObjectPools() {
       return coreMessageObjectPools;
    }
+
+   public void logCommand(Command command, boolean in) {
+      if (logger.isTraceEnabled()) {
+         StringBuilder message = new StringBuilder()
+            .append("OpenWire(")
+            .append(getRemoteAddress())
+            .append(", ")
+            .append(this.getID())
+            .append("):");
+
+         if (in) {
+            message.append(" IN << ");
+         } else {
+            message.append("OUT >> ");
+         }
+
+         message.append((command == null ? "NULL" : command));
+
+         logger.trace(message.toString());
+      }
+   }
 }
diff --git a/docs/user-manual/openwire.adoc b/docs/user-manual/openwire.adoc
index 5bbb1ceb0f..6035638e8e 100644
--- a/docs/user-manual/openwire.adoc
+++ b/docs/user-manual/openwire.adoc
@@ -109,3 +109,11 @@ The mappings support an optional parameter, `selectorAware` which when true, tra
 NOTE: the selector/filter is persisted with the queue binding in the normal way, such that it works independent of connected consumers.
 
 Please see Virtual Topic Mapping example contained in the OpenWire xref:examples.adoc#examples[examples].
+
+== Logging
+
+Incoming and outgoing OpenWire commands can be logged by enabling `TRACE` for `org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection`.
+This can be extremely useful for debugging or simply monitoring client activity.
+Along with the OpenWire command itself the remote IP address of the client is logged as well as the internal connection ID so that commands from the same client can be correlated.
+
+Follow xref:logging.adoc#configuring-a-specific-level-for-a-logger[these steps] to configure logging appropriately.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact