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

Commit afe240a

Browse files
authored
feat: cli output log (#1049)
1 parent af43dc0 commit afe240a

21 files changed

+132
-74
lines changed

engine/commands/chat_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "httplib.h"
33

44
#include "trantor/utils/Logger.h"
5+
#include "utils/logging_utils.h"
56

67
namespace commands {
78
namespace {
@@ -48,12 +49,12 @@ void ChatCmd::Exec(std::string msg) {
4849
data_str.data(), data_str.size(), "application/json");
4950
if (res) {
5051
if (res->status != httplib::StatusCode::OK_200) {
51-
LOG_INFO << res->body;
52+
CTL_ERR(res->body);
5253
return;
5354
}
5455
} else {
5556
auto err = res.error();
56-
LOG_WARN << "HTTP error: " << httplib::to_string(err);
57+
CTL_ERR("HTTP error: " << httplib::to_string(err));
5758
return;
5859
}
5960
}

engine/commands/cmd_info.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cmd_info.h"
22
#include <vector>
33
#include "trantor/utils/Logger.h"
4+
#include "utils/logging_utils.h"
45

56
namespace commands {
67
namespace {
@@ -33,7 +34,7 @@ void CmdInfo::Parse(std::string model_id) {
3334
} else {
3435
auto res = split(model_id, kDelimiter);
3536
if (res.size() != 2) {
36-
LOG_ERROR << "model_id does not valid";
37+
CTL_ERR("<model_id> does not valid");
3738
return;
3839
} else {
3940
model_name = std::move(res[0]);
@@ -45,7 +46,7 @@ void CmdInfo::Parse(std::string model_id) {
4546
} else if (branch.find("gguf") != std::string::npos) {
4647
engine_name = "cortex.llamacpp";
4748
} else {
48-
LOG_ERROR << "Not a valid branch model_name " << branch;
49+
CTL_ERR("Not a valid branch model_name " << branch);
4950
}
5051
}
5152
}

engine/commands/engine_init_cmd.cc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ EngineInitCmd::EngineInitCmd(std::string engineName, std::string version)
2020

2121
bool EngineInitCmd::Exec() const {
2222
if (engineName_.empty()) {
23-
LOG_ERROR << "Engine name is required";
23+
CTL_ERR("Engine name is required");
2424
return false;
2525
}
2626

2727
// Check if the architecture and OS are supported
2828
auto system_info = system_info_utils::GetSystemInfo();
2929
if (system_info.arch == system_info_utils::kUnsupported ||
3030
system_info.os == system_info_utils::kUnsupported) {
31-
LOG_ERROR << "Unsupported OS or architecture: " << system_info.os << ", "
32-
<< system_info.arch;
31+
CTL_ERR("Unsupported OS or architecture: " << system_info.os << ", "
32+
<< system_info.arch);
3333
return false;
3434
}
35-
LOG_INFO << "OS: " << system_info.os << ", Arch: " << system_info.arch;
35+
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
3636

3737
// check if engine is supported
3838
if (std::find(supportedEngines_.begin(), supportedEngines_.end(),
3939
engineName_) == supportedEngines_.end()) {
40-
LOG_ERROR << "Engine not supported";
40+
CTL_ERR("Engine not supported");
4141
return false;
4242
}
4343

@@ -46,7 +46,7 @@ bool EngineInitCmd::Exec() const {
4646
std::ostringstream engineReleasePath;
4747
engineReleasePath << "/repos/janhq/" << engineName_ << "/releases/"
4848
<< version;
49-
LOG_INFO << "Engine release path: " << gitHubHost << engineReleasePath.str();
49+
CTL_INF("Engine release path: " << gitHubHost << engineReleasePath.str());
5050
using namespace nlohmann;
5151

5252
httplib::Client cli(gitHubHost);
@@ -64,10 +64,10 @@ bool EngineInitCmd::Exec() const {
6464
}
6565

6666
auto cuda_driver_version = system_info_utils::GetCudaVersion();
67-
LOG_INFO << "Engine: " << engineName_
68-
<< ", CUDA driver version: " << cuda_driver_version;
67+
CTL_INF("engineName_: " << engineName_);
68+
CTL_INF("CUDA version: " << cuda_driver_version);
69+
std::string matched_variant = "";
6970

70-
std::string matched_variant{""};
7171
if (engineName_ == "cortex.tensorrt-llm") {
7272
matched_variant = engine_matcher_utils::ValidateTensorrtLlm(
7373
variants, system_info.os, cuda_driver_version);
@@ -80,9 +80,9 @@ bool EngineInitCmd::Exec() const {
8080
variants, system_info.os, system_info.arch, suitable_avx,
8181
cuda_driver_version);
8282
}
83-
LOG_INFO << "Matched variant: " << matched_variant;
83+
CTL_INF("Matched variant: " << matched_variant);
8484
if (matched_variant.empty()) {
85-
LOG_ERROR << "No variant found for " << os_arch;
85+
CTL_ERR("No variant found for " << os_arch);
8686
return false;
8787
}
8888

@@ -95,7 +95,7 @@ bool EngineInitCmd::Exec() const {
9595
std::string path = full_url.substr(host.length());
9696

9797
auto fileName = asset["name"].get<std::string>();
98-
LOG_INFO << "URL: " << full_url;
98+
CTL_INF("URL: " << full_url);
9999

100100
auto downloadTask = DownloadTask{.id = engineName_,
101101
.type = DownloadType::Engine,
@@ -115,8 +115,8 @@ bool EngineInitCmd::Exec() const {
115115
bool unused) {
116116
// try to unzip the downloaded file
117117
std::filesystem::path downloadedEnginePath{absolute_path};
118-
LOG_INFO << "Downloaded engine path: "
119-
<< downloadedEnginePath.string();
118+
CTL_INF(
119+
"Downloaded engine path: " << downloadedEnginePath.string());
120120

121121
std::filesystem::path extract_path =
122122
downloadedEnginePath.parent_path().parent_path();
@@ -156,9 +156,9 @@ bool EngineInitCmd::Exec() const {
156156
try {
157157
std::filesystem::remove(absolute_path);
158158
} catch (const std::exception& e) {
159-
LOG_ERROR << "Could not delete file: " << e.what();
159+
CTL_WRN("Could not delete file: " << e.what());
160160
}
161-
LOG_INFO << "Finished!";
161+
CTL_INF("Finished!");
162162
});
163163
if (system_info.os == "mac" || engineName_ == "cortex.onnx") {
164164
// mac and onnx engine does not require cuda toolkit
@@ -192,9 +192,9 @@ bool EngineInitCmd::Exec() const {
192192
// cuda driver version should be greater than toolkit version to ensure compatibility
193193
if (semantic_version_utils::CompareSemanticVersion(
194194
cuda_driver_version, suitable_toolkit_version) < 0) {
195-
LOG_ERROR << "Your Cuda driver version " << cuda_driver_version
195+
CTL_ERR("Your Cuda driver version " << cuda_driver_version
196196
<< " is not compatible with cuda toolkit version "
197-
<< suitable_toolkit_version;
197+
<< suitable_toolkit_version);
198198
return false;
199199
}
200200

@@ -233,7 +233,7 @@ bool EngineInitCmd::Exec() const {
233233
try {
234234
std::filesystem::remove(absolute_path);
235235
} catch (std::exception& e) {
236-
LOG_ERROR << "Error removing downloaded file: " << e.what();
236+
CTL_ERR("Error removing downloaded file: " << e.what());
237237
}
238238
});
239239

@@ -245,12 +245,12 @@ bool EngineInitCmd::Exec() const {
245245
return false;
246246
}
247247
} else {
248-
LOG_ERROR << "HTTP error: " << res->status;
248+
CTL_ERR("HTTP error: " << res->status);
249249
return false;
250250
}
251251
} else {
252252
auto err = res.error();
253-
LOG_ERROR << "HTTP error: " << httplib::to_string(err);
253+
CTL_ERR("HTTP error: " << httplib::to_string(err));
254254
return false;
255255
}
256256
return true;

engine/commands/model_get_cmd.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#include <filesystem>
33
#include <iostream>
44
#include <vector>
5+
#include "cmd_info.h"
56
#include "config/yaml_config.h"
67
#include "trantor/utils/Logger.h"
78
#include "utils/cortex_utils.h"
9+
#include "utils/logging_utils.h"
810

911
namespace commands {
1012

@@ -14,12 +16,15 @@ ModelGetCmd::ModelGetCmd(std::string model_handle)
1416
void ModelGetCmd::Exec() {
1517
if (std::filesystem::exists(cortex_utils::models_folder) &&
1618
std::filesystem::is_directory(cortex_utils::models_folder)) {
19+
CmdInfo ci(model_handle_);
20+
std::string model_file =
21+
ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch;
1722
bool found_model = false;
1823
// Iterate through directory
1924
for (const auto& entry :
2025
std::filesystem::directory_iterator(cortex_utils::models_folder)) {
2126

22-
if (entry.is_regular_file() && entry.path().stem() == model_handle_ &&
27+
if (entry.is_regular_file() && entry.path().stem() == model_file &&
2328
entry.path().extension() == ".yaml") {
2429
try {
2530
config::YamlHandler handler;
@@ -131,11 +136,16 @@ void ModelGetCmd::Exec() {
131136
found_model = true;
132137
break;
133138
} catch (const std::exception& e) {
134-
LOG_ERROR << "Error reading yaml file '" << entry.path().string()
135-
<< "': " << e.what();
139+
CTL_ERR("Error reading yaml file '" << entry.path().string()
140+
<< "': " << e.what());
136141
}
137142
}
138143
}
144+
if (!found_model) {
145+
CLI_LOG("Model not found!");
146+
}
147+
} else {
148+
CLI_LOG("Model not found!");
139149
}
140150
}
141151
}; // namespace commands

engine/commands/model_list_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vector>
99
#include "config/yaml_config.h"
1010
#include "trantor/utils/Logger.h"
11+
#include "utils/logging_utils.h"
1112
namespace commands {
1213

1314
void ModelListCmd::Exec() {
@@ -30,8 +31,8 @@ void ModelListCmd::Exec() {
3031
table.add_row({std::to_string(count), model_config.id,
3132
model_config.engine, model_config.version});
3233
} catch (const std::exception& e) {
33-
LOG_ERROR << "Error reading yaml file '" << entry.path().string()
34-
<< "': " << e.what();
34+
CTL_ERR("Error reading yaml file '" << entry.path().string()
35+
<< "': " << e.what());
3536
}
3637
}
3738
}

engine/commands/model_pull_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "trantor/utils/Logger.h"
55
#include "utils/cortexso_parser.h"
66
#include "utils/model_callback_utils.h"
7+
#include "utils/logging_utils.h"
78

89
namespace commands {
910
ModelPullCmd::ModelPullCmd(std::string model_handle, std::string branch)
@@ -15,10 +16,10 @@ bool ModelPullCmd::Exec() {
1516
DownloadService downloadService;
1617
downloadService.AddDownloadTask(downloadTask.value(),
1718
model_callback_utils::DownloadModelCb);
18-
std::cout << "Download finished" << std::endl;
19+
CTL_INF("Download finished");
1920
return true;
2021
} else {
21-
std::cout << "Model not found" << std::endl;
22+
CTL_ERR("Model not found");
2223
return false;
2324
}
2425
}

engine/commands/model_start_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "httplib.h"
33
#include "nlohmann/json.hpp"
44
#include "trantor/utils/Logger.h"
5+
#include "utils/logging_utils.h"
56

67
namespace commands {
78
ModelStartCmd::ModelStartCmd(std::string host, int port,
@@ -32,11 +33,11 @@ bool ModelStartCmd::Exec() {
3233
data_str.data(), data_str.size(), "application/json");
3334
if (res) {
3435
if (res->status == httplib::StatusCode::OK_200) {
35-
LOG_INFO << res->body;
36+
CLI_LOG("Model loaded!");
3637
}
3738
} else {
3839
auto err = res.error();
39-
LOG_WARN << "HTTP error: " << httplib::to_string(err);
40+
CTL_ERR("HTTP error: " << httplib::to_string(err));
4041
return false;
4142
}
4243
return true;

engine/commands/stop_model_cmd.cc renamed to engine/commands/model_stop_cmd.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#include "stop_model_cmd.h"
1+
#include "model_stop_cmd.h"
22
#include "httplib.h"
33
#include "nlohmann/json.hpp"
44
#include "trantor/utils/Logger.h"
5+
#include "utils/logging_utils.h"
56

67
namespace commands {
7-
StopModelCmd::StopModelCmd(std::string host, int port,
8+
ModelStopCmd::ModelStopCmd(std::string host, int port,
89
const config::ModelConfig& mc)
910
: host_(std::move(host)), port_(port), mc_(mc) {}
1011

11-
void StopModelCmd::Exec() {
12+
void ModelStopCmd::Exec() {
1213
httplib::Client cli(host_ + ":" + std::to_string(port_));
1314
nlohmann::json json_data;
1415
json_data["model"] = mc_.name;
@@ -20,11 +21,12 @@ void StopModelCmd::Exec() {
2021
data_str.data(), data_str.size(), "application/json");
2122
if (res) {
2223
if (res->status == httplib::StatusCode::OK_200) {
23-
LOG_INFO << res->body;
24+
// LOG_INFO << res->body;
25+
CLI_LOG("Model unloaded!");
2426
}
2527
} else {
2628
auto err = res.error();
27-
LOG_WARN << "HTTP error: " << httplib::to_string(err);
29+
CTL_ERR("HTTP error: " << httplib::to_string(err));
2830
}
2931
}
3032

engine/commands/stop_model_cmd.h renamed to engine/commands/model_stop_cmd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace commands {
77

8-
class StopModelCmd{
8+
class ModelStopCmd{
99
public:
10-
StopModelCmd(std::string host, int port, const config::ModelConfig& mc);
10+
ModelStopCmd(std::string host, int port, const config::ModelConfig& mc);
1111
void Exec();
1212

1313
private:

engine/commands/run_cmd.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ void RunCmd::Exec() {
3434
{
3535
if (!IsEngineExisted(ci.engine_name)) {
3636
EngineInitCmd eic(ci.engine_name, "");
37-
if (!eic.Exec())
37+
if (!eic.Exec()) {
38+
LOG_INFO << "Failed to install engine";
3839
return;
40+
}
3941
}
4042
}
4143

0 commit comments

Comments
 (0)