diff --git a/cpp/core/internal/client_proxy.cc b/cpp/core/internal/client_proxy.cc index d8f752b5..f995452c 100644 --- a/cpp/core/internal/client_proxy.cc +++ b/cpp/core/internal/client_proxy.cc @@ -49,7 +49,7 @@ std::string ClientProxy::GetLocalEndpointId() { if (local_endpoint_id_.empty()) { local_endpoint_id_ = GenerateLocalEndpointId(); NEARBY_LOG(INFO, - "ClientProxy [Local Endpoint Generated]: client=%x" PRIx64 + "ClientProxy [Local Endpoint Generated]: client=%" PRIx64 "; endpoint_id=%s", GetClientId(), local_endpoint_id_.c_str()); } @@ -61,7 +61,7 @@ std::string ClientProxy::GenerateLocalEndpointId() { if (!local_high_vis_mode_cache_endpoint_id_.empty()) { NEARBY_LOG(INFO, "ClientProxy [Local Endpoint Re-using cached endpoint id]: " - "client=%x" PRIx64 + "client=%" PRIx64 "; local_high_vis_mode_cache_endpoint_id_=%s", GetClientId(), local_high_vis_mode_cache_endpoint_id_.c_str()); return local_high_vis_mode_cache_endpoint_id_; @@ -92,14 +92,14 @@ void ClientProxy::StartedAdvertising( absl::Span mediums, const ConnectionOptions& advertising_options) { MutexLock lock(&mutex_); - NEARBY_LOG(INFO, "ClientProxy [StartedAdvertising]: client=%x" PRIx64, + NEARBY_LOG(INFO, "ClientProxy [StartedAdvertising]: client=%" PRIx64, GetClientId()); if (high_vis_mode_) { local_high_vis_mode_cache_endpoint_id_ = local_endpoint_id_; NEARBY_LOG(INFO, "ClientProxy [High Visibility Mode Adv, Cache EndpointId]: " - "client=%x" PRIx64 "; local_high_vis_mode_cache_endpoint_id_=%s", + "client=%" PRIx64 "; local_high_vis_mode_cache_endpoint_id_=%s", GetClientId(), local_high_vis_mode_cache_endpoint_id_.c_str()); CancelClearLocalHighVisModeCacheEndpointIdAlarm(); } @@ -110,7 +110,7 @@ void ClientProxy::StartedAdvertising( void ClientProxy::StoppedAdvertising() { MutexLock lock(&mutex_); - NEARBY_LOG(INFO, "ClientProxy [StoppedAdvertising]: client=%x" PRIx64, + NEARBY_LOG(INFO, "ClientProxy [StoppedAdvertising]: client=%" PRIx64, GetClientId()); if (IsAdvertising()) { @@ -258,7 +258,7 @@ void ClientProxy::OnConnectionInitiated(const std::string& endpoint_id, bool inserted = result.second; NEARBY_LOG( INFO, - "ClientProxy [Connection Initiated]: add Connection: client=%x" PRIx64 + "ClientProxy [Connection Initiated]: add Connection: client=%" PRIx64 "; endpoint_id=%s; inserted=%d", GetClientId(), endpoint_id.c_str(), inserted); DCHECK(inserted); @@ -279,9 +279,10 @@ void ClientProxy::OnConnectionAccepted(const std::string& endpoint_id) { MutexLock lock(&mutex_); if (!HasPendingConnectionToEndpoint(endpoint_id)) { - NEARBY_LOG( - INFO, "ClientProxy [Connection Accepted]: no pending connection; id=%s", - endpoint_id.c_str()); + NEARBY_LOG(INFO, + "ClientProxy [Connection Accepted]: no pending connection; " + "endpoint_id=%s", + endpoint_id.c_str()); return; } @@ -298,9 +299,10 @@ void ClientProxy::OnConnectionRejected(const std::string& endpoint_id, MutexLock lock(&mutex_); if (!HasPendingConnectionToEndpoint(endpoint_id)) { - NEARBY_LOG( - INFO, "ClientProxy [Connection Rejected]: no pending connection; id=%s", - endpoint_id.c_str()); + NEARBY_LOG(INFO, + "ClientProxy [Connection Rejected]: no pending connection; " + "endpoint_id=%s", + endpoint_id.c_str()); return; } @@ -320,7 +322,7 @@ void ClientProxy::OnBandwidthChanged(const std::string& endpoint_id, if (item != nullptr) { item->connection_listener.bandwidth_changed_cb(endpoint_id, new_medium); NEARBY_LOG(INFO, - "ClientProxy [reporting onBandwidthChanged]: client=%x" PRIx64 + "ClientProxy [reporting onBandwidthChanged]: client=%" PRIx64 "; endpoint_id=%s", GetClientId(), endpoint_id.c_str()); } @@ -583,7 +585,7 @@ void ClientProxy::OnPayload(const std::string& endpoint_id, Payload payload) { if (item != nullptr) { NEARBY_LOG(INFO, "ClientProxy [reporting onPayloadReceived]: " - "client=%x" PRIx64 "; endpoint_id=%s; payload_id=%x" PRIx64, + "client=%" PRIx64 "; endpoint_id=%s; payload_id=%" PRIx64, GetClientId(), endpoint_id.c_str(), static_cast(payload.GetId())); item->payload_listener.payload_cb(endpoint_id, std::move(payload)); @@ -615,14 +617,14 @@ void ClientProxy::OnPayloadProgress(const std::string& endpoint_id, if (info.status == PayloadProgressInfo::Status::kInProgress) { NEARBY_LOG(VERBOSE, "ClientProxy [reporting onPayloadProgress]: " - "client=%x" PRIx64 "; endpoint_id=%s; payload_id=%x" PRIx64 + "client=%" PRIx64 "; endpoint_id=%s; payload_id=%" PRIx64 ", payload_status=%d", GetClientId(), endpoint_id.c_str(), info.payload_id, info.status); } else { NEARBY_LOG(INFO, "ClientProxy [reporting onPayloadProgress]: " - "client=%x" PRIx64 "; endpoint_id=%s; payload_id=%x" PRIx64 + "client=%" PRIx64 "; endpoint_id=%s; payload_id=%" PRIx64 ", payload_status=%d", GetClientId(), endpoint_id.c_str(), info.payload_id, info.status); @@ -685,7 +687,7 @@ ConnectionOptions ClientProxy::GetDiscoveryOptions() const { void ClientProxy::EnterHighVisibilityMode() { MutexLock lock(&mutex_); - NEARBY_LOG(INFO, "ClientProxy [EnterHighVisibilityMode]: client=%x" PRIx64, + NEARBY_LOG(INFO, "ClientProxy [EnterHighVisibilityMode]: client=%" PRIx64, GetClientId()); high_vis_mode_ = true; @@ -693,7 +695,7 @@ void ClientProxy::EnterHighVisibilityMode() { void ClientProxy::ExitHighVisibilityMode() { MutexLock lock(&mutex_); - NEARBY_LOG(INFO, "ClientProxy [ExitHighVisibilityMode]: client=%x" PRIx64, + NEARBY_LOG(INFO, "ClientProxy [ExitHighVisibilityMode]: client=%" PRIx64, GetClientId()); high_vis_mode_ = false; @@ -706,7 +708,7 @@ void ClientProxy::ScheduleClearLocalHighVisModeCacheEndpointIdAlarm() { if (local_high_vis_mode_cache_endpoint_id_.empty()) { NEARBY_LOG(VERBOSE, "ClientProxy [There is no cached local high power advertising " - "endpoint Id.]: client=%x" PRIx64, + "endpoint Id.]: client=%" PRIx64, GetClientId()); return; } @@ -715,7 +717,7 @@ void ClientProxy::ScheduleClearLocalHighVisModeCacheEndpointIdAlarm() { // 30s. NEARBY_LOG(INFO, "ClientProxy [High Visibility Mode Adv, Schedule to Clear Cache " - "EndpointId]: client=%x" PRIx64 + "EndpointId]: client=%" PRIx64 "; local_high_vis_mode_cache_endpoint_id_=%s", GetClientId(), local_high_vis_mode_cache_endpoint_id_.c_str()); clear_local_high_vis_mode_cache_endpoint_id_alarm_ = CancelableAlarm( @@ -724,7 +726,7 @@ void ClientProxy::ScheduleClearLocalHighVisModeCacheEndpointIdAlarm() { MutexLock lock(&mutex_); NEARBY_LOG(INFO, "ClientProxy [Cleared cached local high power advertising " - "endpoint Id.]: client=%x" PRIx64 + "endpoint Id.]: client=%" PRIx64 "; local_high_vis_mode_cache_endpoint_id_=%s", GetClientId(), local_high_vis_mode_cache_endpoint_id_.c_str()); diff --git a/cpp/core/internal/offline_service_controller.cc b/cpp/core/internal/offline_service_controller.cc index 3dc7085c..91afe0bc 100644 --- a/cpp/core/internal/offline_service_controller.cc +++ b/cpp/core/internal/offline_service_controller.cc @@ -14,6 +14,7 @@ #include "core/internal/offline_service_controller.h" +#include #include #include "absl/strings/str_join.h" @@ -25,26 +26,26 @@ namespace connections { OfflineServiceController::~OfflineServiceController() { Stop(); } void OfflineServiceController::Stop() { - NEARBY_LOGS(INFO) << "Initiating shutdown of OfflineServiceController."; + NEARBY_LOG(INFO, "Initiating shutdown of OfflineServiceController."); if (stop_.Set(true)) return; payload_manager_.DisconnectFromEndpointManager(); pcp_manager_.DisconnectFromEndpointManager(); - NEARBY_LOGS(INFO) << "OfflineServiceController has shut down."; + NEARBY_LOG(INFO, "OfflineServiceController has shut down."); } Status OfflineServiceController::StartAdvertising( ClientProxy* client, const std::string& service_id, const ConnectionOptions& options, const ConnectionRequestInfo& info) { if (stop_) return {Status::kOutOfOrderApiCall}; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " requested advertising to start."; + NEARBY_LOG(INFO, "Client %" PRIx64 " requested advertising to start.", + client->GetClientId()); return pcp_manager_.StartAdvertising(client, service_id, options, info); } void OfflineServiceController::StopAdvertising(ClientProxy* client) { if (stop_) return; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " requested advertising to stop."; + NEARBY_LOG(INFO, "Client %" PRIx64 " requested advertising to stop.", + client->GetClientId()); pcp_manager_.StopAdvertising(client); } @@ -52,15 +53,15 @@ Status OfflineServiceController::StartDiscovery( ClientProxy* client, const std::string& service_id, const ConnectionOptions& options, const DiscoveryListener& listener) { if (stop_) return {Status::kOutOfOrderApiCall}; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " requested discovery to start."; + NEARBY_LOG(INFO, "Client %" PRIx64 " requested discovery to start.", + client->GetClientId()); return pcp_manager_.StartDiscovery(client, service_id, options, listener); } void OfflineServiceController::StopDiscovery(ClientProxy* client) { if (stop_) return; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " requested discovery to stop."; + NEARBY_LOG(INFO, "Client %" PRIx64 " requested discovery to stop.", + client->GetClientId()); pcp_manager_.StopDiscovery(client); } @@ -75,8 +76,9 @@ Status OfflineServiceController::RequestConnection( ClientProxy* client, const std::string& endpoint_id, const ConnectionRequestInfo& info, const ConnectionOptions& options) { if (stop_) return {Status::kOutOfOrderApiCall}; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " requested a connection to endpoint id=" << endpoint_id; + NEARBY_LOG(INFO, + "Client %" PRIx64 " requested a connection to endpoint_id=%s", + client->GetClientId(), endpoint_id.c_str()); return pcp_manager_.RequestConnection(client, endpoint_id, info, options); } @@ -84,27 +86,28 @@ Status OfflineServiceController::AcceptConnection( ClientProxy* client, const std::string& endpoint_id, const PayloadListener& listener) { if (stop_) return {Status::kOutOfOrderApiCall}; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " accepted the connection with endpoint id=" - << endpoint_id; + NEARBY_LOG(INFO, + "Client %" PRIx64 " accepted the connection with endpoint_id=%s", + client->GetClientId(), endpoint_id.c_str()); return pcp_manager_.AcceptConnection(client, endpoint_id, listener); } Status OfflineServiceController::RejectConnection( ClientProxy* client, const std::string& endpoint_id) { if (stop_) return {Status::kOutOfOrderApiCall}; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " rejected the connection with endpoint id=" - << endpoint_id; + NEARBY_LOG(INFO, + "Client %" PRIx64 " rejected the connection with endpoint_id=%s", + client->GetClientId(), endpoint_id.c_str()); return pcp_manager_.RejectConnection(client, endpoint_id); } void OfflineServiceController::InitiateBandwidthUpgrade( ClientProxy* client, const std::string& endpoint_id) { if (stop_) return; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " initiated a manual bandwidth upgrade with endpoint id=" - << endpoint_id; + NEARBY_LOG(INFO, + "Client %" PRIx64 + " initiated a manual bandwidth upgrade with endpoint_id=%s", + client->GetClientId(), endpoint_id.c_str()); bwu_manager_.InitiateBwuForEndpoint(client, endpoint_id); } @@ -112,27 +115,28 @@ void OfflineServiceController::SendPayload( ClientProxy* client, const std::vector& endpoint_ids, Payload payload) { if (stop_) return; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " is sending payload=" << payload.GetId() - << " to endpoint ids=" - << "{" << absl::StrJoin(endpoint_ids, ",").c_str() << "}"; + NEARBY_LOG(INFO, + "Client %" PRIx64 " is sending payload_id=%" PRIx64 + " to endpoint_ids={%s}", + client->GetClientId(), static_cast(payload.GetId()), + absl::StrJoin(endpoint_ids, ",").c_str()); payload_manager_.SendPayload(client, endpoint_ids, std::move(payload)); } Status OfflineServiceController::CancelPayload(ClientProxy* client, std::int64_t payload_id) { if (stop_) return {Status::kOutOfOrderApiCall}; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " cancelled payload=" << payload_id; + NEARBY_LOG(INFO, "Client %" PRIx64 " cancelled payload_id=%" PRIx64, + client->GetClientId(), static_cast(payload_id)); return payload_manager_.CancelPayload(client, payload_id); } void OfflineServiceController::DisconnectFromEndpoint( ClientProxy* client, const std::string& endpoint_id) { if (stop_) return; - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " requested a disconnection from endpoint id=" - << endpoint_id; + NEARBY_LOG( + INFO, "Client %" PRIx64 " requested a disconnection from endpoint_id=%s", + client->GetClientId(), endpoint_id.c_str()); endpoint_manager_.UnregisterEndpoint(client, endpoint_id); } diff --git a/cpp/core/internal/offline_service_controller_test.cc b/cpp/core/internal/offline_service_controller_test.cc index 4707dfd8..eef60baf 100644 --- a/cpp/core/internal/offline_service_controller_test.cc +++ b/cpp/core/internal/offline_service_controller_test.cc @@ -346,11 +346,11 @@ TEST_P(OfflineServiceControllerTest, CanDisconnect) { OfflineSimulationUser user_a(kDeviceA, GetParam()); OfflineSimulationUser user_b(kDeviceB, GetParam()); ASSERT_TRUE(SetupConnection(user_a, user_b)); - NEARBY_LOGS(INFO) << "Disconnecting"; + NEARBY_LOG(INFO, "Disconnecting"); user_b.ExpectDisconnect(disconnect_latch); user_b.Disconnect(); EXPECT_TRUE(disconnect_latch.Await(kDisconnectTimeout).result()); - NEARBY_LOGS(INFO) << "Disconnected"; + NEARBY_LOG(INFO, "Disconnected"); EXPECT_FALSE(user_b.IsConnected()); user_a.Stop(); user_b.Stop(); diff --git a/cpp/core/internal/service_controller_router.cc b/cpp/core/internal/service_controller_router.cc index 70a368f9..1ecd12c6 100644 --- a/cpp/core/internal/service_controller_router.cc +++ b/cpp/core/internal/service_controller_router.cc @@ -14,6 +14,7 @@ #include "core/internal/service_controller_router.h" +#include #include #include #include @@ -50,11 +51,11 @@ const std::size_t kMaxEndpointInfoLength = 131u; ServiceControllerRouter::ServiceControllerRouter( std::function factory) : service_controller_factory_(std::move(factory)) { - NEARBY_LOGS(INFO) << "ServiceControllerRouter going up."; + NEARBY_LOG(INFO, "ServiceControllerRouter going up."); } ServiceControllerRouter::~ServiceControllerRouter() { - NEARBY_LOGS(INFO) << "ServiceControllerRouter going down."; + NEARBY_LOG(INFO, "ServiceControllerRouter going down."); if (service_controller_) { service_controller_->Stop(); @@ -224,11 +225,11 @@ void ServiceControllerRouter::AcceptConnection(ClientProxy* client, } if (client->HasLocalEndpointResponded(endpoint_id)) { - NEARBY_LOGS(WARNING) - << "Client " << client->GetClientId() - << " invoked acceptConnectionRequest() after having already " - "accepted/rejected the connection to endpoint(id=" - << endpoint_id << ")"; + NEARBY_LOG(WARNING, + "Client %" PRIx64 + " invoked acceptConnectionRequest() after having already " + "accepted/rejected the connection to endpoint(id=%s)", + client->GetClientId(), endpoint_id.c_str()); callback.result_cb({Status::kOutOfOrderApiCall}); return; } @@ -257,11 +258,11 @@ void ServiceControllerRouter::RejectConnection(ClientProxy* client, } if (client->HasLocalEndpointResponded(endpoint_id)) { - NEARBY_LOGS(WARNING) - << "Client " << client->GetClientId() - << " invoked rejectConnectionRequest() after having already " - "accepted/rejected the connection to endpoint(id=" - << endpoint_id << ")"; + NEARBY_LOG(WARNING, + "Client %" PRIx64 + " invoked rejectConnectionRequest() after having already " + "accepted/rejected the connection to endpoint(id=%s)", + client->GetClientId(), endpoint_id.c_str()); callback.result_cb({Status::kOutOfOrderApiCall}); return; } @@ -372,10 +373,12 @@ void ServiceControllerRouter::StopAllEndpoints(ClientProxy* client, RouteToServiceController("scr-stop-all-endpoints", [this, client, callback]() { - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " has requested us to stop all endpoints. We will now " - "reset the client."; - if (ClientHasAcquiredServiceController(client)) { + NEARBY_LOG(INFO, + "Client %" PRIx64 + " has requested us to stop all endpoints. We will now reset the " + "client.", + client->GetClientId()); + if (ClientHasAcquiredServiceController(client)) { DoneWithStrategySessionForClient(client); } callback.result_cb({Status::kSuccess}); @@ -392,8 +395,9 @@ void ServiceControllerRouter::ClientDisconnecting( callback]() { if (ClientHasAcquiredServiceController(client)) { DoneWithStrategySessionForClient(client); - NEARBY_LOGS(INFO) << "Client " << client->GetClientId() - << " has completed the client's connection."; + NEARBY_LOG(INFO, + "Client %" PRIx64 " has completed the client's connection.", + client->GetClientId()); } callback.result_cb({Status::kSuccess}); }); @@ -426,14 +430,14 @@ Status ServiceControllerRouter::AcquireServiceControllerForClient( bool is_the_only_client_of_service_controller = clients_.size() == 1 && ClientHasAcquiredServiceController(client); if (!is_the_only_client_of_service_controller) { - NEARBY_LOGS(INFO) << "Client has already active strategy."; + NEARBY_LOG(INFO, "Client has already active strategy."); return {Status::kAlreadyHaveActiveStrategy}; } // If the client still has connected endpoints, they must disconnect before // they can switch. if (!client->GetConnectedEndpoints().empty()) { - NEARBY_LOGS(INFO) << "Client has connected endpoints."; + NEARBY_LOG(INFO, "Client has connected endpoints."); return {Status::kOutOfOrderApiCall}; } @@ -500,7 +504,7 @@ bool ServiceControllerRouter::ClientHasConnectionToAtLeastOneEndpoint( Status ServiceControllerRouter::UpdateCurrentServiceControllerAndStrategy( Strategy strategy) { if (!strategy.IsValid()) { - NEARBY_LOGS(INFO) << "Strategy is not valid."; + NEARBY_LOG(INFO, "Strategy is not valid."); return {Status::kError}; }