Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 1e1c5e0

Browse files
Fix/isolate stdout cli server (#1511)
* chore: change update to patch * fix: swagger * fix: pull api * fix: separate log for CLI and API * fix: comment * fix: comment --------- Co-authored-by: vansangpfiev <vansangpfiev@gmail.com>
1 parent c4272a6 commit 1e1c5e0

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

engine/commands/cortex_upd_cmd.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool ReplaceBinaryInflight(const std::filesystem::path& src,
143143
// Get permissions of the executable file
144144
struct stat dst_file_stat;
145145
if (stat(dst.string().c_str(), &dst_file_stat) != 0) {
146-
CTL_ERR("Error getting permissions of executable file: " << dst.string());
146+
CLI_LOG_ERROR("Error getting permissions of executable file: " << dst.string());
147147
return false;
148148
}
149149

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

167167
// Set owner and group of the executable file
168168
if (chown(dst.string().c_str(), dst_file_owner, dst_file_group) != 0) {
169-
CTL_ERR(
169+
CLI_LOG_ERROR(
170170
"Error setting owner and group of executable file: " << dst.string());
171171
restore_binary();
172172
return false;
173173
}
174174

175175
// Remove cortex_temp
176176
if (unlink(temp.string().c_str()) != 0) {
177-
CTL_ERR("Error deleting self: " << strerror(errno));
177+
CLI_LOG_ERROR("Error deleting self: " << strerror(errno));
178178
restore_binary();
179179
return false;
180180
}
181181
#endif
182182
} catch (const std::exception& e) {
183-
CTL_ERR("Something went wrong: " << e.what());
183+
CLI_LOG_ERROR("Something went wrong: " << e.what());
184184
restore_binary();
185185
return false;
186186
}
@@ -254,16 +254,16 @@ bool CortexUpdCmd::GetStable(const std::string& v) {
254254
return false;
255255
}
256256
} catch (const nlohmann::json::parse_error& e) {
257-
CTL_ERR("JSON parse error: " << e.what());
257+
CLI_LOG_ERROR("JSON parse error: " << e.what());
258258
return false;
259259
}
260260
} else {
261-
CTL_ERR("HTTP error: " << res->status);
261+
CLI_LOG_ERROR("HTTP error: " << res->status);
262262
return false;
263263
}
264264
} else {
265265
auto err = res.error();
266-
CTL_ERR("HTTP error: " << httplib::to_string(err));
266+
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
267267
return false;
268268
}
269269

@@ -320,16 +320,16 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
320320
return false;
321321
}
322322
} catch (const nlohmann::json::parse_error& e) {
323-
CTL_ERR("JSON parse error: " << e.what());
323+
CLI_LOG_ERROR("JSON parse error: " << e.what());
324324
return false;
325325
}
326326
} else {
327-
CTL_ERR("HTTP error: " << res->status);
327+
CLI_LOG_ERROR("HTTP error: " << res->status);
328328
return false;
329329
}
330330
} else {
331331
auto err = res.error();
332-
CTL_ERR("HTTP error: " << httplib::to_string(err));
332+
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
333333
return false;
334334
}
335335

@@ -364,7 +364,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
364364
CTL_INF(asset_name);
365365
}
366366
if (matched_variant.empty()) {
367-
CTL_ERR("No variant found for " << os_arch);
367+
CLI_LOG_ERROR("No variant found for " << os_arch);
368368
return false;
369369
}
370370
CTL_INF("Matched variant: " << matched_variant);
@@ -383,7 +383,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
383383
std::filesystem::create_directories(local_path.parent_path());
384384
}
385385
} catch (const std::filesystem::filesystem_error& e) {
386-
CTL_ERR("Failed to create directories: " << e.what());
386+
CLI_LOG_ERROR("Failed to create directories: " << e.what());
387387
return false;
388388
}
389389
auto download_task{DownloadTask{.id = "cortex",
@@ -410,7 +410,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
410410
CTL_INF("Finished!");
411411
});
412412
if (result.has_error()) {
413-
CTL_ERR("Failed to download: " << result.error());
413+
CLI_LOG_ERROR("Failed to download: " << result.error());
414414
}
415415
break;
416416
}
@@ -447,7 +447,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
447447
std::filesystem::create_directories(localPath.parent_path());
448448
}
449449
} catch (const std::filesystem::filesystem_error& e) {
450-
CTL_ERR("Failed to create directories: " << e.what());
450+
CLI_LOG_ERROR("Failed to create directories: " << e.what());
451451
return false;
452452
}
453453
auto download_task =
@@ -474,7 +474,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
474474
CTL_INF("Finished!");
475475
});
476476
if (result.has_error()) {
477-
CTL_ERR("Failed to download: " << result.error());
477+
CLI_LOG_ERROR("Failed to download: " << result.error());
478478
return false;
479479
}
480480

engine/commands/engine_get_cmd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ void EngineGetCmd::Exec(const std::string& host, int port,
3939
v["status"].asString()});
4040

4141
} else {
42-
CTL_ERR("Failed to get engine list with status code: " << res->status);
42+
CLI_LOG_ERROR("Failed to get engine list with status code: " << res->status);
4343
return;
4444
}
4545
} else {
4646
auto err = res.error();
47-
CTL_ERR("HTTP error: " << httplib::to_string(err));
47+
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
4848
return;
4949
}
5050

engine/commands/engine_list_cmd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ bool EngineListCmd::Exec(const std::string& host, int port) {
4141
}
4242
}
4343
} else {
44-
CTL_ERR("Failed to get engine list with status code: " << res->status);
44+
CLI_LOG_ERROR("Failed to get engine list with status code: " << res->status);
4545
return false;
4646
}
4747
} else {
4848
auto err = res.error();
49-
CTL_ERR("HTTP error: " << httplib::to_string(err));
49+
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
5050
return false;
5151
}
5252

engine/commands/model_alias_cmd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ void ModelAliasCmd::Exec(const std::string& host, int port,
3131
CLI_LOG("Successfully set model alias '" + model_alias +
3232
"' for modeID '" + model_handle + "'.");
3333
} else {
34-
CTL_ERR("Model failed to set alias with status code: " << res->status);
34+
CLI_LOG_ERROR("Model failed to set alias with status code: " << res->status);
3535
}
3636
} else {
3737
auto err = res.error();
38-
CTL_ERR("HTTP error: " << httplib::to_string(err));
38+
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
3939
}
4040
}
4141

engine/commands/server_stop_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void ServerStopCmd::Exec() {
1313
CLI_LOG("Server stopped!");
1414
} else {
1515
auto err = res.error();
16-
CTL_ERR("HTTP error: " << httplib::to_string(err));
16+
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
1717
}
1818
}
1919

engine/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
117117
auto system_info = system_info_utils::GetSystemInfo();
118118
if (system_info->arch == system_info_utils::kUnsupported ||
119119
system_info->os == system_info_utils::kUnsupported) {
120-
CTL_ERR("Unsupported OS or architecture: " << system_info->os << ", "
120+
CLI_LOG_ERROR("Unsupported OS or architecture: " << system_info->os << ", "
121121
<< system_info->arch);
122122
return 1;
123123
}

engine/utils/logging_utils.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ inline bool log_verbose = false;
2222
}
2323

2424
// Use std::cout if not verbose, use trantor log if verbose
25-
#define CTL_ERR(msg) \
25+
#define CTL_ERR(msg) LOG_ERROR << msg;
26+
27+
#define CLI_LOG(msg) \
2628
if (log_verbose) { \
27-
LOG_ERROR << msg; \
29+
LOG_INFO << msg; \
2830
} else { \
29-
LOG_ERROR << msg; \
3031
std::cout << msg << std::endl; \
3132
}
32-
33-
#define CLI_LOG(msg) \
33+
#define CLI_LOG_ERROR(msg) \
3434
if (log_verbose) { \
3535
LOG_INFO << msg; \
3636
} else { \
37+
LOG_ERROR << msg; \
3738
std::cout << msg << std::endl; \
38-
}
39+
}

0 commit comments

Comments
 (0)