Don't stringify PeerAddress in SendPreparedMessage if not logging it. (#32821)
diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp
index dfcbd60..b821820 100644
--- a/src/transport/SessionManager.cpp
+++ b/src/transport/SessionManager.cpp
@@ -448,10 +448,10 @@
{
CHIP_ERROR err = mTransportMgr->SendMessage(*destination, std::move(msgBuf));
#if CHIP_ERROR_LOGGING
- char addressStr[Transport::PeerAddress::kMaxToStringSize] = { 0 };
- destination->ToString(addressStr);
if (err != CHIP_NO_ERROR)
{
+ char addressStr[Transport::PeerAddress::kMaxToStringSize] = { 0 };
+ destination->ToString(addressStr);
ChipLogError(Inet, "SendMessage() to %s failed: %" CHIP_ERROR_FORMAT, addressStr, err.Format());
}
#endif // CHIP_ERROR_LOGGING