提交 f92df0d0 编写于 作者: G groot 提交者: xj.lin

refine log code


Former-commit-id: b043a1372bf79e3fc7dc9a277ba2cc62bbfc32ba
上级 22d2236f
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
......@@ -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();
......
......@@ -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 <fcntl.h>
#include <sys/stat.h>
......@@ -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;
}
......
......@@ -5,7 +5,6 @@
******************************************************************************/
#pragma once
#include "ServerConfig.h"
#include "utils/Error.h"
#include <cstdint>
......@@ -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
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -4,17 +4,54 @@
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include "LogUtil.h"
#include "server/ServerConfig.h"
#include <easylogging++.h>
#include <ctype.h>
namespace zilliz {
namespace vecwise {
namespace server {
int32_t InitLog() {
#if 0
ServerConfig &config = ServerConfig::GetInstance();
ConfigNode log_config = config.GetConfig(CONFIG_LOG);
const std::map<std::string, ConfigNode>& 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");
el::Loggers::reconfigureAllLoggers(conf);
#endif
el::Loggers::reconfigureAllLoggers(conf);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册