diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/AmqpShutdownSignal.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/AmqpShutdownSignal.java
index e9e3c9665b2ab..cca9f7d4c8952 100644
--- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/AmqpShutdownSignal.java
+++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/AmqpShutdownSignal.java
@@ -48,21 +48,13 @@ public boolean isInitiatedByClient() {
return isInitiatedByClient;
}
- public LoggingEventBuilder addContext(LoggingEventBuilder logBuilder) {
- return logBuilder
- .addKeyValue("isTransient", isTransient)
- .addKeyValue("isInitiatedByClient", isInitiatedByClient)
- .addKeyValue("shutdownMessage", message);
- }
-
/**
* Returns String representing this {@code AmqpShutdownSignal} signal.
*
- * To write logs, please use {@link AmqpShutdownSignal#addContext} instead.
+ * To write logs, please use {@link com.azure.core.amqp.implementation.AmqpLoggingUtils#addShutdownSignal(LoggingEventBuilder, AmqpShutdownSignal)}.
*/
@Override
public String toString() {
- return String.format(Locale.US, "%s, isTransient[%s], initiatedByClient[%s]", message, isTransient,
- isInitiatedByClient);
+ return message;
}
}
diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpExceptionHandler.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpExceptionHandler.java
index fa02f50883bd0..9e88e86eaaa8f 100644
--- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpExceptionHandler.java
+++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpExceptionHandler.java
@@ -7,6 +7,8 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.ClientLogger;
+import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addShutdownSignal;
+
/**
* Handles exceptions generated by AMQP connections, sessions, and/or links.
*/
@@ -34,7 +36,6 @@ void onConnectionError(Throwable exception) {
* @param shutdownSignal The shutdown signal that was received.
*/
void onConnectionShutdown(AmqpShutdownSignal shutdownSignal) {
- shutdownSignal
- .addContext(logger.atInfo()).log("Shutdown received");
+ addShutdownSignal(logger.atInfo(), shutdownSignal).log("Shutdown received");
}
}
diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpLoggingUtils.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpLoggingUtils.java
index d00d778047b77..a34faa72a2c7b 100644
--- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpLoggingUtils.java
+++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/AmqpLoggingUtils.java
@@ -1,5 +1,6 @@
package com.azure.core.amqp.implementation;
+import com.azure.core.amqp.AmqpShutdownSignal;
import com.azure.core.util.logging.LoggingEventBuilder;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import reactor.core.publisher.SignalType;
@@ -29,5 +30,13 @@ public static LoggingEventBuilder addErrorCondition(LoggingEventBuilder logBuild
.addKeyValue(ERROR_CONDITION_KEY, errorCondition.getCondition())
.addKeyValue(ERROR_DESCRIPTION_KEY, errorCondition.getDescription());
}
+
+ public static LoggingEventBuilder addShutdownSignal(LoggingEventBuilder logBuilder, AmqpShutdownSignal shutdownSignal) {
+ return logBuilder
+ .addKeyValue("isTransient", shutdownSignal.isTransient())
+ .addKeyValue("isInitiatedByClient", shutdownSignal.isInitiatedByClient())
+ // will call toString() if logging is enabled
+ .addKeyValue("shutdownMessage", shutdownSignal);
+ }
}
diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ReactorConnection.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ReactorConnection.java
index 851eb1bbdd4dd..9d27d166874de 100644
--- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ReactorConnection.java
+++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ReactorConnection.java
@@ -41,6 +41,7 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
+import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addShutdownSignal;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addSignalTypeAndResult;
import static com.azure.core.amqp.implementation.ClientConstants.CONNECTION_ID_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.EMIT_RESULT_KEY;
@@ -423,12 +424,12 @@ public Mono closeAsync() {
}
Mono closeAsync(AmqpShutdownSignal shutdownSignal) {
- shutdownSignal.addContext(logger.atInfo()).log("Disposing of ReactorConnection.");
+ addShutdownSignal(logger.atInfo(), shutdownSignal).log("Disposing of ReactorConnection.");
final Sinks.EmitResult result = shutdownSignalSink.tryEmitValue(shutdownSignal);
if (result.isFailure()) {
// It's possible that another one was already emitted, so it's all good.
- shutdownSignal.addContext(logger.atInfo())
+ addShutdownSignal(logger.atInfo(), shutdownSignal)
.addKeyValue(EMIT_RESULT_KEY, result)
.log("Unable to emit shutdown signal.");
}
@@ -618,7 +619,7 @@ public void onConnectionError(Throwable exception) {
@Override
void onConnectionShutdown(AmqpShutdownSignal shutdownSignal) {
- shutdownSignal.addContext(logger.atInfo())
+ addShutdownSignal(logger.atInfo(), shutdownSignal)
.addKeyValue(FULLY_QUALIFIED_NAMESPACE_KEY, getFullyQualifiedNamespace())
.log("onConnectionShutdown. Shutting down.");