diff --git a/engine/commands/cortex_upd_cmd.cc b/engine/commands/cortex_upd_cmd.cc index 2d2caea8a..fb71a054e 100644 --- a/engine/commands/cortex_upd_cmd.cc +++ b/engine/commands/cortex_upd_cmd.cc @@ -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; } @@ -159,14 +159,14 @@ 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; @@ -174,13 +174,13 @@ bool ReplaceBinaryInflight(const std::filesystem::path& src, // 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; } @@ -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; } @@ -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; } @@ -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); @@ -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", @@ -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; } @@ -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 = @@ -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; } diff --git a/engine/commands/engine_get_cmd.cc b/engine/commands/engine_get_cmd.cc index 96180e49a..7d4c66bb5 100644 --- a/engine/commands/engine_get_cmd.cc +++ b/engine/commands/engine_get_cmd.cc @@ -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; } diff --git a/engine/commands/engine_list_cmd.cc b/engine/commands/engine_list_cmd.cc index c34bef1aa..cc2d38a02 100644 --- a/engine/commands/engine_list_cmd.cc +++ b/engine/commands/engine_list_cmd.cc @@ -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; } diff --git a/engine/commands/model_alias_cmd.cc b/engine/commands/model_alias_cmd.cc index 08a0c88a0..05d35e023 100644 --- a/engine/commands/model_alias_cmd.cc +++ b/engine/commands/model_alias_cmd.cc @@ -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)); } } diff --git a/engine/commands/server_stop_cmd.cc b/engine/commands/server_stop_cmd.cc index 4f48506cb..e55446923 100644 --- a/engine/commands/server_stop_cmd.cc +++ b/engine/commands/server_stop_cmd.cc @@ -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)); } } diff --git a/engine/main.cc b/engine/main.cc index 339b7c12a..02e93b8f1 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -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; } diff --git a/engine/utils/logging_utils.h b/engine/utils/logging_utils.h index c143c2177..f4376cb01 100644 --- a/engine/utils/logging_utils.h +++ b/engine/utils/logging_utils.h @@ -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; \ - } + } \ No newline at end of file