refactor(navigation): 将日志输出从格式化字符串改为字符串拼接

修改日志输出方式,使用字符串拼接替代格式化字符串,提高代码一致性并减少潜在的类型安全问题
This commit is contained in:
2025-09-21 14:55:05 +08:00
parent 093bdf18b4
commit ff895ff2ed

View File

@@ -15,9 +15,9 @@ void Navigation::Init() {
try {
client_ = std::make_unique<unitree::robot::Client>(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<bool>()) {
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<std::string>());
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<int>()) + ", Info: " + response_json.value("info", "").get<std::string>());
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;
}
}