Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/isolate stdout cli server #1511

Merged
merged 15 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions engine/commands/cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool ReplaceBinaryInflight(const std::filesystem::path& src,
// Get permissions of the executable file
struct stat dst_file_stat;
if (stat(dst.string().c_str(), &dst_file_stat) != 0) {
CTL_ERR("Error getting permissions of executable file: " << dst.string());
CLI_LOG_ERROR("Error getting permissions of executable file: " << dst.string());
return false;
}

Expand All @@ -159,28 +159,28 @@ bool ReplaceBinaryInflight(const std::filesystem::path& src,
#if !defined(_WIN32)
// Set permissions of the executable file
if (chmod(dst.string().c_str(), dst_file_stat.st_mode) != 0) {
CTL_ERR("Error setting permissions of executable file: " << dst.string());
CLI_LOG_ERROR("Error setting permissions of executable file: " << dst.string());
restore_binary();
return false;
}

// Set owner and group of the executable file
if (chown(dst.string().c_str(), dst_file_owner, dst_file_group) != 0) {
CTL_ERR(
CLI_LOG_ERROR(
"Error setting owner and group of executable file: " << dst.string());
restore_binary();
return false;
}

// Remove cortex_temp
if (unlink(temp.string().c_str()) != 0) {
CTL_ERR("Error deleting self: " << strerror(errno));
CLI_LOG_ERROR("Error deleting self: " << strerror(errno));
restore_binary();
return false;
}
#endif
} catch (const std::exception& e) {
CTL_ERR("Something went wrong: " << e.what());
CLI_LOG_ERROR("Something went wrong: " << e.what());
restore_binary();
return false;
}
Expand Down Expand Up @@ -254,16 +254,16 @@ bool CortexUpdCmd::GetStable(const std::string& v) {
return false;
}
} catch (const nlohmann::json::parse_error& e) {
CTL_ERR("JSON parse error: " << e.what());
CLI_LOG_ERROR("JSON parse error: " << e.what());
return false;
}
} else {
CTL_ERR("HTTP error: " << res->status);
CLI_LOG_ERROR("HTTP error: " << res->status);
return false;
}
} else {
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
return false;
}

Expand Down Expand Up @@ -320,16 +320,16 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
return false;
}
} catch (const nlohmann::json::parse_error& e) {
CTL_ERR("JSON parse error: " << e.what());
CLI_LOG_ERROR("JSON parse error: " << e.what());
return false;
}
} else {
CTL_ERR("HTTP error: " << res->status);
CLI_LOG_ERROR("HTTP error: " << res->status);
return false;
}
} else {
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
return false;
}

Expand Down Expand Up @@ -364,7 +364,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
CTL_INF(asset_name);
}
if (matched_variant.empty()) {
CTL_ERR("No variant found for " << os_arch);
CLI_LOG_ERROR("No variant found for " << os_arch);
return false;
}
CTL_INF("Matched variant: " << matched_variant);
Expand All @@ -383,7 +383,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
std::filesystem::create_directories(local_path.parent_path());
}
} catch (const std::filesystem::filesystem_error& e) {
CTL_ERR("Failed to create directories: " << e.what());
CLI_LOG_ERROR("Failed to create directories: " << e.what());
return false;
}
auto download_task{DownloadTask{.id = "cortex",
Expand All @@ -410,7 +410,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
CTL_INF("Finished!");
});
if (result.has_error()) {
CTL_ERR("Failed to download: " << result.error());
CLI_LOG_ERROR("Failed to download: " << result.error());
}
break;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
std::filesystem::create_directories(localPath.parent_path());
}
} catch (const std::filesystem::filesystem_error& e) {
CTL_ERR("Failed to create directories: " << e.what());
CLI_LOG_ERROR("Failed to create directories: " << e.what());
return false;
}
auto download_task =
Expand All @@ -474,7 +474,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
CTL_INF("Finished!");
});
if (result.has_error()) {
CTL_ERR("Failed to download: " << result.error());
CLI_LOG_ERROR("Failed to download: " << result.error());
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions engine/commands/engine_get_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ void EngineGetCmd::Exec(const std::string& host, int port,
v["status"].asString()});

} else {
CTL_ERR("Failed to get engine list with status code: " << res->status);
CLI_LOG_ERROR("Failed to get engine list with status code: " << res->status);
return;
}
} else {
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions engine/commands/engine_list_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ bool EngineListCmd::Exec(const std::string& host, int port) {
}
}
} else {
CTL_ERR("Failed to get engine list with status code: " << res->status);
CLI_LOG_ERROR("Failed to get engine list with status code: " << res->status);
return false;
}
} else {
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions engine/commands/model_alias_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ void ModelAliasCmd::Exec(const std::string& host, int port,
CLI_LOG("Successfully set model alias '" + model_alias +
"' for modeID '" + model_handle + "'.");
} else {
CTL_ERR("Model failed to set alias with status code: " << res->status);
CLI_LOG_ERROR("Model failed to set alias with status code: " << res->status);
}
} else {
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/commands/server_stop_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void ServerStopCmd::Exec() {
CLI_LOG("Server stopped!");
} else {
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
auto system_info = system_info_utils::GetSystemInfo();
if (system_info->arch == system_info_utils::kUnsupported ||
system_info->os == system_info_utils::kUnsupported) {
CTL_ERR("Unsupported OS or architecture: " << system_info->os << ", "
CLI_LOG_ERROR("Unsupported OS or architecture: " << system_info->os << ", "
<< system_info->arch);
return 1;
}
Expand Down
13 changes: 7 additions & 6 deletions engine/utils/logging_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ inline bool log_verbose = false;
}

// Use std::cout if not verbose, use trantor log if verbose
#define CTL_ERR(msg) \
#define CTL_ERR(msg) LOG_ERROR << msg;

#define CLI_LOG(msg) \
if (log_verbose) { \
LOG_ERROR << msg; \
LOG_INFO << msg; \
} else { \
LOG_ERROR << msg; \
std::cout << msg << std::endl; \
}

#define CLI_LOG(msg) \
#define CLI_LOG_ERROR(msg) \
if (log_verbose) { \
LOG_INFO << msg; \
} else { \
LOG_ERROR << msg; \
std::cout << msg << std::endl; \
}
}
Loading