From ff895ff2edf0c9b6815af010bd53a5ad7e3cdd52 Mon Sep 17 00:00:00 2001 From: Sucan126 <632190820@qq.com> Date: Sun, 21 Sep 2025 14:55:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor(navigation):=20=E5=B0=86=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BE=93=E5=87=BA=E4=BB=8E=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=94=B9=E4=B8=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改日志输出方式,使用字符串拼接替代格式化字符串,提高代码一致性并减少潜在的类型安全问题 --- src/navigation.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/navigation.cpp b/src/navigation.cpp index 9593cdb..01559f7 100644 --- a/src/navigation.cpp +++ b/src/navigation.cpp @@ -15,9 +15,9 @@ void Navigation::Init() { try { client_ = std::make_unique(SLAM_SERVICE_NAME); client_->Init(); - LOG_INFO("Navigation client for service '{}' initialized.", SLAM_SERVICE_NAME); + LOG_INFO("Navigation client for service '" + SLAM_SERVICE_NAME + "' initialized."); } catch (const std::exception& e) { - LOG_ERROR("Failed to initialize navigation client: {}", e.what()); + LOG_ERROR("Failed to initialize navigation client: " + std::string(e.what())); } } @@ -32,29 +32,29 @@ bool Navigation::callSlamService(int api_id, const nlohmann::json& data) { std::string request_str = request_json.dump(); std::string response_str; - LOG_INFO("Calling slam service api_id: {}, request: {}", api_id, request_str); + LOG_INFO("Calling slam service api_id: " + std::to_string(api_id) + ", request: " + request_str); int ret = client_->Call(api_id, request_str, response_str); if (ret != 0) { - LOG_ERROR("Slam service request failed with SDK error code: {}", ret); + LOG_ERROR("Slam service request failed with SDK error code: " + std::to_string(ret)); return false; } - LOG_INFO("Slam service response: {}", response_str); + LOG_INFO("Slam service response: " + response_str); try { nlohmann::json response_json = nlohmann::json::parse(response_str); if (response_json.contains("succeed") && response_json["succeed"].get()) { - LOG_INFO("Slam service call for api_id {} succeeded. Info: {}", api_id, response_json.value("info", "")); + LOG_INFO("Slam service call for api_id " + std::to_string(api_id) + " succeeded. Info: " + response_json.value("info", "").get()); return true; } else { - LOG_ERROR("Slam service call for api_id {} failed. Error code: {}, Info: {}", - api_id, response_json.value("errorCode", -1), response_json.value("info", "")); + LOG_ERROR("Slam service call for api_id " + std::to_string(api_id) + " failed. Error code: " + + std::to_string(response_json.value("errorCode", -1).get()) + ", Info: " + response_json.value("info", "").get()); return false; } } catch (const nlohmann::json::parse_error& e) { - LOG_ERROR("Failed to parse slam service response: {}", e.what()); + LOG_ERROR("Failed to parse slam service response: " + std::string(e.what())); return false; } }