refactor(navigation): 将日志输出从格式化字符串改为字符串拼接
修改日志输出方式,使用字符串拼接替代格式化字符串,提高代码一致性并减少潜在的类型安全问题
This commit is contained in:
@@ -15,9 +15,9 @@ void Navigation::Init() {
|
|||||||
try {
|
try {
|
||||||
client_ = std::make_unique<unitree::robot::Client>(SLAM_SERVICE_NAME);
|
client_ = std::make_unique<unitree::robot::Client>(SLAM_SERVICE_NAME);
|
||||||
client_->Init();
|
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) {
|
} 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 request_str = request_json.dump();
|
||||||
std::string response_str;
|
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);
|
int ret = client_->Call(api_id, request_str, response_str);
|
||||||
|
|
||||||
if (ret != 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Slam service response: {}", response_str);
|
LOG_INFO("Slam service response: " + response_str);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json response_json = nlohmann::json::parse(response_str);
|
nlohmann::json response_json = nlohmann::json::parse(response_str);
|
||||||
if (response_json.contains("succeed") && response_json["succeed"].get<bool>()) {
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Slam service call for api_id {} failed. Error code: {}, Info: {}",
|
LOG_ERROR("Slam service call for api_id " + std::to_string(api_id) + " failed. Error code: " +
|
||||||
api_id, response_json.value("errorCode", -1), response_json.value("info", ""));
|
std::to_string(response_json.value("errorCode", -1).get<int>()) + ", Info: " + response_json.value("info", "").get<std::string>());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (const nlohmann::json::parse_error& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user