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

Commit e5e506a

Browse files
fix: log level does not work for macOS (#1703)
* feat: API for configuring huggingface token * chore: API docs * chore: Token docs * chore: docs * fix: log level * fix: logging issue --------- Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent 37fecbd commit e5e506a

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

docs/sidebars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const sidebars: SidebarsConfig = {
104104
type: "doc",
105105
id: "configurations/token",
106106
label: "Token",
107-
}
107+
},
108108
],
109109
},
110110
{

engine/services/engine_service.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ cpp::result<void, std::string> EngineService::LoadEngine(
899899
CTL_WRN("Method SetFileLogger is not supported yet");
900900
}
901901
if (en->IsSupported("SetLogLevel")) {
902-
en->SetLogLevel(trantor::Logger::logLevel());
902+
en->SetLogLevel(logging_utils_helper::global_log_level);
903903
} else {
904904
CTL_WRN("Method SetLogLevel is not supported yet");
905905
}

engine/services/hardware_service.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ HardwareInfo HardwareService::GetHardwareInfo() {
5757
}
5858

5959
bool HardwareService::Restart(const std::string& host, int port) {
60+
namespace luh = logging_utils_helper;
6061
if (!ahc_)
6162
return true;
6263
auto exe = commands::GetCortexServerBinary();
@@ -117,6 +118,7 @@ bool HardwareService::Restart(const std::string& host, int port) {
117118
std::string params = "--ignore_cout";
118119
params += " --config_file_path " + get_config_file_path();
119120
params += " --data_folder_path " + get_data_folder_path();
121+
params += " --loglevel " + luh::LogLevelStr(luh::global_log_level);
120122
std::string cmds = cortex_utils::GetCurrentPath() + "/" + exe + " " + params;
121123
// Create child process
122124
if (!CreateProcess(
@@ -168,7 +170,8 @@ bool HardwareService::Restart(const std::string& host, int port) {
168170
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
169171
execl(p.c_str(), exe.c_str(), "--ignore_cout", "--config_file_path",
170172
get_config_file_path().c_str(), "--data_folder_path",
171-
get_data_folder_path().c_str(), "--loglevel", "INFO", (char*)0);
173+
get_data_folder_path().c_str(), "--loglevel",
174+
luh::LogLevelStr(luh::global_log_level).c_str(), (char*)0);
172175
} else {
173176
// Parent process
174177
if (!TryConnectToServer(host, port)) {

engine/utils/logging_utils.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,33 @@ inline bool is_server = false;
3232
}
3333

3434
namespace logging_utils_helper {
35+
// In macOS, the default log level is reset to INFO when we load engine
36+
// Use a global log level to save the value
37+
inline trantor::Logger::LogLevel global_log_level = trantor::Logger::kInfo;
3538
inline void SetLogLevel(const std::string& log_level, bool ignore_cout) {
3639
if (log_level == "TRACE") {
3740
trantor::Logger::setLogLevel(trantor::Logger::kTrace);
41+
global_log_level = trantor::Logger::kTrace;
3842
if (!ignore_cout)
3943
std::cout << "Set log level to TRACE" << std::endl;
4044
} else if (log_level == "DEBUG") {
4145
trantor::Logger::setLogLevel(trantor::Logger::kDebug);
46+
global_log_level = trantor::Logger::kDebug;
4247
if (!ignore_cout)
4348
std::cout << "Set log level to DEBUG" << std::endl;
4449
} else if (log_level == "INFO") {
4550
trantor::Logger::setLogLevel(trantor::Logger::kInfo);
51+
global_log_level = trantor::Logger::kInfo;
4652
if (!ignore_cout)
4753
std::cout << "Set log level to INFO" << std::endl;
4854
} else if (log_level == "WARN") {
4955
trantor::Logger::setLogLevel(trantor::Logger::kWarn);
56+
global_log_level = trantor::Logger::kWarn;
5057
if (!ignore_cout)
5158
std::cout << "Set log level to WARN" << std::endl;
5259
} else if (log_level == "ERROR") {
5360
trantor::Logger::setLogLevel(trantor::Logger::kError);
61+
global_log_level = trantor::Logger::kError;
5462
if (!ignore_cout)
5563
std::cout << "Set log level to ERROR" << std::endl;
5664
} else {
@@ -59,4 +67,21 @@ inline void SetLogLevel(const std::string& log_level, bool ignore_cout) {
5967
<< std::endl;
6068
}
6169
}
70+
71+
inline std::string LogLevelStr(const trantor::Logger::LogLevel& log_level) {
72+
switch (log_level) {
73+
case trantor::Logger::kTrace:
74+
return "TRACE";
75+
case trantor::Logger::kDebug:
76+
return "DEBUG";
77+
case trantor::Logger::kInfo:
78+
return "INFO";
79+
case trantor::Logger::kWarn:
80+
return "WARN";
81+
case trantor::Logger::kError:
82+
return "ERROR";
83+
default:
84+
return "UNKNOWN";
85+
}
86+
}
6287
} // namespace logging_utils_helper

0 commit comments

Comments
 (0)