diff --git a/cpp/conf/server_config.yaml b/cpp/conf/server_config.yaml index 6b23da0ec6..d2b78b583c 100644 --- a/cpp/conf/server_config.yaml +++ b/cpp/conf/server_config.yaml @@ -1,3 +1,31 @@ server_config: address: 127.0.0.1 - port: 21001 \ No newline at end of file + port: 21001 + +log_config: + global: + format: "%datetime | %level | %logger | %msg" + filename: "/tmp/logs/vecwise/vecwise_engine-%datetime{%h:%m}-global.log" + enabled: true + to_file: true + to_standard_output: true + subsecond_precision: 3 + performance_tracking: false + max_log_file_size: 2097152 # throw log files away after 2mb + debug: + filename: "/tmp/logs/vecwise/vecwise_engine-%datetime{%h:%m}-debug.log" + enabled: true + warning: + filename: "/tmp/logs/vecwise/vecwise_engine-%datetime{%h:%m}-warning.log" + trace: + filename: "/tmp/logs/vecwise/vecwise_engine-%datetime{%h:%m}-trace.log" + verbose: + format: "%datetime{%d/%m/%y} | %level-%vlevel | %msg" + to_file: false + to_standard_output: true + error: + enabled: false + filename: "/tmp/logs/vecwise/vecwise_engine-%datetime{%h:%m}-error.log" + fatal: + enabled: false + filename: "/tmp/logs/vecwise/vecwise_engine-%datetime{%h:%m}-fatal.log" \ No newline at end of file diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 03ffd03e07..689f7a7af7 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -14,7 +14,6 @@ #include "utils/SignalUtil.h" #include "utils/CommonUtil.h" -#include "utils/LogUtil.h" INITIALIZE_EASYLOGGINGPP @@ -24,8 +23,6 @@ using namespace zilliz::vecwise; int main(int argc, char *argv[]) { - zilliz::vecwise::server::InitLog(); - printf("Vecwise engine server start...\n"); // zilliz::lib::gpu::InitMemoryAllocator(); diff --git a/cpp/src/server/Server.cpp b/cpp/src/server/Server.cpp index 6d5aa7cafe..0a0f95fb1a 100644 --- a/cpp/src/server/Server.cpp +++ b/cpp/src/server/Server.cpp @@ -4,9 +4,11 @@ // Proprietary and confidential. //////////////////////////////////////////////////////////////////////////////// #include "Server.h" +#include "ServerConfig.h" #include "utils/CommonUtil.h" #include "utils/SignalUtil.h" #include "utils/TimeRecorder.h" +#include "utils/LogUtil.h" #include #include @@ -26,8 +28,7 @@ Server::Instance() { return &server; } -Server::Server() - : opt_config_ptr_(nullptr){ +Server::Server() { } Server::~Server() { @@ -142,12 +143,14 @@ Server::Start() { return 1; } + zilliz::vecwise::server::InitLog(); + //log path is defined by LoadConfig, so InitLog must be called after LoadConfig - ServerConfig *config = ServerConfig::GetInstance(); - ConfigNode server_config = config->GetServerConfig(); + ServerConfig &config = ServerConfig::GetInstance(); + ConfigNode server_config = config.GetConfig(CONFIG_SERVER); //print config into console and log - opt_config_ptr_->PrintAll(); + config.PrintAll(); // Handle Signal signal(SIGINT, SignalUtil::HandleSignal); @@ -206,8 +209,7 @@ Server::Stop() { ServerError Server::LoadConfig() { - opt_config_ptr_ = ServerConfig::GetInstance(); - opt_config_ptr_->LoadConfigFile(config_filename_); + ServerConfig::GetInstance().LoadConfigFile(config_filename_); return SERVER_SUCCESS; } diff --git a/cpp/src/server/Server.h b/cpp/src/server/Server.h index b6ebae1e5b..85478530d1 100644 --- a/cpp/src/server/Server.h +++ b/cpp/src/server/Server.h @@ -5,7 +5,6 @@ ******************************************************************************/ #pragma once -#include "ServerConfig.h" #include "utils/Error.h" #include @@ -41,7 +40,6 @@ class Server { int pid_fd = -1; std::string pid_filename_; std::string config_filename_; - ServerConfig* opt_config_ptr_ = nullptr; }; // Server } // server diff --git a/cpp/src/server/ServerConfig.cpp b/cpp/src/server/ServerConfig.cpp index 09f4c752dd..ffcfd47181 100644 --- a/cpp/src/server/ServerConfig.cpp +++ b/cpp/src/server/ServerConfig.cpp @@ -17,10 +17,13 @@ namespace zilliz { namespace vecwise { namespace server { -ServerConfig* +static const std::string CONFIG_ADDRESS = "address"; +static const std::string CONFIG_PORT = "port"; + +ServerConfig& ServerConfig::GetInstance() { static ServerConfig config; - return &config; + return config; } ServerError @@ -63,28 +66,28 @@ ServerConfig::PrintAll() const { } ConfigNode -ServerConfig::GetServerConfig() const { +ServerConfig::GetConfig(const std::string& name) const { const IConfigMgr* mgr = IConfigMgr::GetInstance(); const ConfigNode& root_node = mgr->GetRootNode(); - return root_node.GetChild(CONFIG_SERVER); + return root_node.GetChild(name); } ConfigNode& -ServerConfig::GetServerConfig() { +ServerConfig::GetConfig(const std::string& name) { IConfigMgr* mgr = IConfigMgr::GetInstance(); ConfigNode& root_node = mgr->GetRootNode(); - return root_node.GetChild(CONFIG_SERVER); + return root_node.GetChild(name); } std::string ServerConfig::GetServerAddress() const { - ConfigNode server_config = GetServerConfig(); + ConfigNode server_config = GetConfig(CONFIG_SERVER); return server_config.GetValue(CONFIG_ADDRESS); } std::string ServerConfig::GetServerPort() const { - ConfigNode server_config = GetServerConfig(); + ConfigNode server_config = GetConfig(CONFIG_SERVER); return server_config.GetValue(CONFIG_PORT); } diff --git a/cpp/src/server/ServerConfig.h b/cpp/src/server/ServerConfig.h index 4277d66066..d3169686bd 100644 --- a/cpp/src/server/ServerConfig.h +++ b/cpp/src/server/ServerConfig.h @@ -15,19 +15,17 @@ namespace vecwise { namespace server { static const std::string CONFIG_SERVER = "server_config"; -static const std::string CONFIG_ADDRESS = "address"; -static const std::string CONFIG_PORT = "port"; - +static const std::string CONFIG_LOG = "log_config"; class ServerConfig { public: - static ServerConfig *GetInstance(); + static ServerConfig &GetInstance(); ServerError LoadConfigFile(const std::string& config_filename); void PrintAll() const; - ConfigNode GetServerConfig() const; - ConfigNode& GetServerConfig(); + ConfigNode GetConfig(const std::string& name) const; + ConfigNode& GetConfig(const std::string& name); std::string GetServerAddress() const; std::string GetServerPort() const; diff --git a/cpp/src/utils/LogUtil.cpp b/cpp/src/utils/LogUtil.cpp index 6614667cd4..e7fd0c8596 100644 --- a/cpp/src/utils/LogUtil.cpp +++ b/cpp/src/utils/LogUtil.cpp @@ -4,17 +4,54 @@ // Proprietary and confidential. //////////////////////////////////////////////////////////////////////////////// #include "LogUtil.h" +#include "server/ServerConfig.h" #include +#include namespace zilliz { namespace vecwise { namespace server { int32_t InitLog() { - el::Configurations conf("../../conf/vecwise_engine_log.conf"); - el::Loggers::reconfigureAllLoggers(conf); +#if 0 + ServerConfig &config = ServerConfig::GetInstance(); + ConfigNode log_config = config.GetConfig(CONFIG_LOG); + const std::map& settings = log_config.GetChildren(); + std::string str_config; + for(auto iter : settings) { + str_config += "* "; + str_config += iter.first; + str_config += ":"; + str_config.append("\n"); + + auto sub_configs = iter.second.GetConfig(); + for(auto it_sub : sub_configs) { + str_config += " "; + str_config += it_sub.first; + str_config += " = "; + std::string temp = it_sub.first; + std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower); + bool is_text = (temp == "format" || temp == "filename"); + if(is_text){ + str_config += "\""; + } + str_config += it_sub.second; + if(is_text){ + str_config += "\""; + } + str_config.append("\n"); + } + } + + el::Configurations conf; + conf.parseFromText(str_config); +#else + el::Configurations conf("../../conf/vecwise_engine_log.conf"); +#endif + + el::Loggers::reconfigureAllLoggers(conf); return 0; }