Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const sidebars: SidebarsConfig = {
type: "doc",
id: "configurations/token",
label: "Token",
}
},
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion engine/services/engine_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ cpp::result<void, std::string> EngineService::LoadEngine(
CTL_WRN("Method SetFileLogger is not supported yet");
}
if (en->IsSupported("SetLogLevel")) {
en->SetLogLevel(trantor::Logger::logLevel());
en->SetLogLevel(logging_utils_helper::global_log_level);
} else {
CTL_WRN("Method SetLogLevel is not supported yet");
}
Expand Down
5 changes: 4 additions & 1 deletion engine/services/hardware_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ HardwareInfo HardwareService::GetHardwareInfo() {
}

bool HardwareService::Restart(const std::string& host, int port) {
namespace luh = logging_utils_helper;
if (!ahc_)
return true;
auto exe = commands::GetCortexServerBinary();
Expand Down Expand Up @@ -117,6 +118,7 @@ bool HardwareService::Restart(const std::string& host, int port) {
std::string params = "--ignore_cout";
params += " --config_file_path " + get_config_file_path();
params += " --data_folder_path " + get_data_folder_path();
params += " --loglevel " + luh::LogLevelStr(luh::global_log_level);
std::string cmds = cortex_utils::GetCurrentPath() + "/" + exe + " " + params;
// Create child process
if (!CreateProcess(
Expand Down Expand Up @@ -168,7 +170,8 @@ bool HardwareService::Restart(const std::string& host, int port) {
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
execl(p.c_str(), exe.c_str(), "--ignore_cout", "--config_file_path",
get_config_file_path().c_str(), "--data_folder_path",
get_data_folder_path().c_str(), "--loglevel", "INFO", (char*)0);
get_data_folder_path().c_str(), "--loglevel",
luh::LogLevelStr(luh::global_log_level).c_str(), (char*)0);
} else {
// Parent process
if (!TryConnectToServer(host, port)) {
Expand Down
25 changes: 25 additions & 0 deletions engine/utils/logging_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,33 @@ inline bool is_server = false;
}

namespace logging_utils_helper {
// In macOS, the default log level is reset to INFO when we load engine
// Use a global log level to save the value
inline trantor::Logger::LogLevel global_log_level = trantor::Logger::kInfo;
inline void SetLogLevel(const std::string& log_level, bool ignore_cout) {
if (log_level == "TRACE") {
trantor::Logger::setLogLevel(trantor::Logger::kTrace);
global_log_level = trantor::Logger::kTrace;
if (!ignore_cout)
std::cout << "Set log level to TRACE" << std::endl;
} else if (log_level == "DEBUG") {
trantor::Logger::setLogLevel(trantor::Logger::kDebug);
global_log_level = trantor::Logger::kDebug;
if (!ignore_cout)
std::cout << "Set log level to DEBUG" << std::endl;
} else if (log_level == "INFO") {
trantor::Logger::setLogLevel(trantor::Logger::kInfo);
global_log_level = trantor::Logger::kInfo;
if (!ignore_cout)
std::cout << "Set log level to INFO" << std::endl;
} else if (log_level == "WARN") {
trantor::Logger::setLogLevel(trantor::Logger::kWarn);
global_log_level = trantor::Logger::kWarn;
if (!ignore_cout)
std::cout << "Set log level to WARN" << std::endl;
} else if (log_level == "ERROR") {
trantor::Logger::setLogLevel(trantor::Logger::kError);
global_log_level = trantor::Logger::kError;
if (!ignore_cout)
std::cout << "Set log level to ERROR" << std::endl;
} else {
Expand All @@ -59,4 +67,21 @@ inline void SetLogLevel(const std::string& log_level, bool ignore_cout) {
<< std::endl;
}
}

inline std::string LogLevelStr(const trantor::Logger::LogLevel& log_level) {
switch (log_level) {
case trantor::Logger::kTrace:
return "TRACE";
case trantor::Logger::kDebug:
return "DEBUG";
case trantor::Logger::kInfo:
return "INFO";
case trantor::Logger::kWarn:
return "WARN";
case trantor::Logger::kError:
return "ERROR";
default:
return "UNKNOWN";
}
}
} // namespace logging_utils_helper
Loading