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