Github user franz1981 commented on a diff in the pull request: https://github.com/apache/activemq-artemis/pull/1592#discussion_r145358049 --- Diff: artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTUtil.java --- @@ -149,16 +160,62 @@ public static void logMessage(MQTTSessionState state, MqttMessage message, boole if (message.fixedHeader() != null) { log.append(message.fixedHeader().messageType().toString()); - if (message.variableHeader() instanceof MqttPublishVariableHeader) { - log.append("(" + ((MqttPublishVariableHeader) message.variableHeader()).messageId() + ") " + message.fixedHeader().qosLevel()); - } else if (message.variableHeader() instanceof MqttMessageIdVariableHeader) { + if (message.variableHeader() instanceof MqttMessageIdVariableHeader) { log.append("(" + ((MqttMessageIdVariableHeader) message.variableHeader()).messageId() + ")"); } - if (message.fixedHeader().messageType() == MqttMessageType.SUBSCRIBE) { - for (MqttTopicSubscription sub : ((MqttSubscribeMessage) message).payload().topicSubscriptions()) { - log.append("\n\t" + sub.topicName() + " : " + sub.qualityOfService()); - } + switch (message.fixedHeader().messageType()) { + case PUBLISH: + MqttPublishVariableHeader publishHeader = (MqttPublishVariableHeader) message.variableHeader(); + log.append("(" + publishHeader.packetId() + ")") + .append(" topic=" + publishHeader.topicName()) + .append(", qos=" + message.fixedHeader().qosLevel()) + .append(", retain=" + message.fixedHeader().isRetain()) + .append(", dup=" + message.fixedHeader().isDup()); + if (logUTF8PublishPayload != null) { + log.append(" payload=" + ((MqttPublishMessage)message).payload().toString(StandardCharsets.UTF_8)); + } + break; + case CONNECT: + MqttConnectVariableHeader connectHeader = (MqttConnectVariableHeader) message.variableHeader(); + MqttConnectPayload payload = ((MqttConnectMessage)message).payload(); + log.append(" name=").append(connectHeader.name()) + .append(", version=").append(connectHeader.version()) --- End diff -- @jbertram In order to avoid the JVM to compile `logMessage` with a big method (killing futher optimisations of the caller) I suggest to move the log message building it in a separate method (eg `private static void traceMessage(...)`) and use a pattern of calls like this: ``` public static void logMessage(MQTTSessionState state, MqttMessage message, boolean inbound) { if (logger.isTraceEnabled()) { traceMessage(state, message, inbound); } } ``` This will let the JVM inline the `logMessage` call when is not needed.
---