mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 18:38:44 +08:00
refine log code
Former-commit-id: b043a1372bf79e3fc7dc9a277ba2cc62bbfc32ba
This commit is contained in:
parent
22d2236f42
commit
f92df0d044
@ -1,3 +1,31 @@
|
|||||||
server_config:
|
server_config:
|
||||||
address: 127.0.0.1
|
address: 127.0.0.1
|
||||||
port: 21001
|
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"
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include "utils/SignalUtil.h"
|
#include "utils/SignalUtil.h"
|
||||||
#include "utils/CommonUtil.h"
|
#include "utils/CommonUtil.h"
|
||||||
#include "utils/LogUtil.h"
|
|
||||||
|
|
||||||
INITIALIZE_EASYLOGGINGPP
|
INITIALIZE_EASYLOGGINGPP
|
||||||
|
|
||||||
@ -24,8 +23,6 @@ using namespace zilliz::vecwise;
|
|||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
zilliz::vecwise::server::InitLog();
|
|
||||||
|
|
||||||
printf("Vecwise engine server start...\n");
|
printf("Vecwise engine server start...\n");
|
||||||
|
|
||||||
// zilliz::lib::gpu::InitMemoryAllocator();
|
// zilliz::lib::gpu::InitMemoryAllocator();
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
// Proprietary and confidential.
|
// Proprietary and confidential.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
|
#include "ServerConfig.h"
|
||||||
#include "utils/CommonUtil.h"
|
#include "utils/CommonUtil.h"
|
||||||
#include "utils/SignalUtil.h"
|
#include "utils/SignalUtil.h"
|
||||||
#include "utils/TimeRecorder.h"
|
#include "utils/TimeRecorder.h"
|
||||||
|
#include "utils/LogUtil.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -26,8 +28,7 @@ Server::Instance() {
|
|||||||
return &server;
|
return &server;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::Server()
|
Server::Server() {
|
||||||
: opt_config_ptr_(nullptr){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Server::~Server() {
|
Server::~Server() {
|
||||||
@ -142,12 +143,14 @@ Server::Start() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zilliz::vecwise::server::InitLog();
|
||||||
|
|
||||||
//log path is defined by LoadConfig, so InitLog must be called after LoadConfig
|
//log path is defined by LoadConfig, so InitLog must be called after LoadConfig
|
||||||
ServerConfig *config = ServerConfig::GetInstance();
|
ServerConfig &config = ServerConfig::GetInstance();
|
||||||
ConfigNode server_config = config->GetServerConfig();
|
ConfigNode server_config = config.GetConfig(CONFIG_SERVER);
|
||||||
|
|
||||||
//print config into console and log
|
//print config into console and log
|
||||||
opt_config_ptr_->PrintAll();
|
config.PrintAll();
|
||||||
|
|
||||||
// Handle Signal
|
// Handle Signal
|
||||||
signal(SIGINT, SignalUtil::HandleSignal);
|
signal(SIGINT, SignalUtil::HandleSignal);
|
||||||
@ -206,8 +209,7 @@ Server::Stop() {
|
|||||||
|
|
||||||
ServerError
|
ServerError
|
||||||
Server::LoadConfig() {
|
Server::LoadConfig() {
|
||||||
opt_config_ptr_ = ServerConfig::GetInstance();
|
ServerConfig::GetInstance().LoadConfigFile(config_filename_);
|
||||||
opt_config_ptr_->LoadConfigFile(config_filename_);
|
|
||||||
|
|
||||||
return SERVER_SUCCESS;
|
return SERVER_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ServerConfig.h"
|
|
||||||
#include "utils/Error.h"
|
#include "utils/Error.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -41,7 +40,6 @@ class Server {
|
|||||||
int pid_fd = -1;
|
int pid_fd = -1;
|
||||||
std::string pid_filename_;
|
std::string pid_filename_;
|
||||||
std::string config_filename_;
|
std::string config_filename_;
|
||||||
ServerConfig* opt_config_ptr_ = nullptr;
|
|
||||||
}; // Server
|
}; // Server
|
||||||
|
|
||||||
} // server
|
} // server
|
||||||
|
@ -17,10 +17,13 @@ namespace zilliz {
|
|||||||
namespace vecwise {
|
namespace vecwise {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
ServerConfig*
|
static const std::string CONFIG_ADDRESS = "address";
|
||||||
|
static const std::string CONFIG_PORT = "port";
|
||||||
|
|
||||||
|
ServerConfig&
|
||||||
ServerConfig::GetInstance() {
|
ServerConfig::GetInstance() {
|
||||||
static ServerConfig config;
|
static ServerConfig config;
|
||||||
return &config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerError
|
ServerError
|
||||||
@ -63,28 +66,28 @@ ServerConfig::PrintAll() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConfigNode
|
ConfigNode
|
||||||
ServerConfig::GetServerConfig() const {
|
ServerConfig::GetConfig(const std::string& name) const {
|
||||||
const IConfigMgr* mgr = IConfigMgr::GetInstance();
|
const IConfigMgr* mgr = IConfigMgr::GetInstance();
|
||||||
const ConfigNode& root_node = mgr->GetRootNode();
|
const ConfigNode& root_node = mgr->GetRootNode();
|
||||||
return root_node.GetChild(CONFIG_SERVER);
|
return root_node.GetChild(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigNode&
|
ConfigNode&
|
||||||
ServerConfig::GetServerConfig() {
|
ServerConfig::GetConfig(const std::string& name) {
|
||||||
IConfigMgr* mgr = IConfigMgr::GetInstance();
|
IConfigMgr* mgr = IConfigMgr::GetInstance();
|
||||||
ConfigNode& root_node = mgr->GetRootNode();
|
ConfigNode& root_node = mgr->GetRootNode();
|
||||||
return root_node.GetChild(CONFIG_SERVER);
|
return root_node.GetChild(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
ServerConfig::GetServerAddress() const {
|
ServerConfig::GetServerAddress() const {
|
||||||
ConfigNode server_config = GetServerConfig();
|
ConfigNode server_config = GetConfig(CONFIG_SERVER);
|
||||||
return server_config.GetValue(CONFIG_ADDRESS);
|
return server_config.GetValue(CONFIG_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
ServerConfig::GetServerPort() const {
|
ServerConfig::GetServerPort() const {
|
||||||
ConfigNode server_config = GetServerConfig();
|
ConfigNode server_config = GetConfig(CONFIG_SERVER);
|
||||||
return server_config.GetValue(CONFIG_PORT);
|
return server_config.GetValue(CONFIG_PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,19 +15,17 @@ namespace vecwise {
|
|||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
static const std::string CONFIG_SERVER = "server_config";
|
static const std::string CONFIG_SERVER = "server_config";
|
||||||
static const std::string CONFIG_ADDRESS = "address";
|
static const std::string CONFIG_LOG = "log_config";
|
||||||
static const std::string CONFIG_PORT = "port";
|
|
||||||
|
|
||||||
|
|
||||||
class ServerConfig {
|
class ServerConfig {
|
||||||
public:
|
public:
|
||||||
static ServerConfig *GetInstance();
|
static ServerConfig &GetInstance();
|
||||||
|
|
||||||
ServerError LoadConfigFile(const std::string& config_filename);
|
ServerError LoadConfigFile(const std::string& config_filename);
|
||||||
void PrintAll() const;
|
void PrintAll() const;
|
||||||
|
|
||||||
ConfigNode GetServerConfig() const;
|
ConfigNode GetConfig(const std::string& name) const;
|
||||||
ConfigNode& GetServerConfig();
|
ConfigNode& GetConfig(const std::string& name);
|
||||||
|
|
||||||
std::string GetServerAddress() const;
|
std::string GetServerAddress() const;
|
||||||
std::string GetServerPort() const;
|
std::string GetServerPort() const;
|
||||||
|
@ -4,17 +4,54 @@
|
|||||||
// Proprietary and confidential.
|
// Proprietary and confidential.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "LogUtil.h"
|
#include "LogUtil.h"
|
||||||
|
#include "server/ServerConfig.h"
|
||||||
|
|
||||||
#include <easylogging++.h>
|
#include <easylogging++.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
namespace zilliz {
|
namespace zilliz {
|
||||||
namespace vecwise {
|
namespace vecwise {
|
||||||
namespace server {
|
namespace server {
|
||||||
|
|
||||||
int32_t InitLog() {
|
int32_t InitLog() {
|
||||||
el::Configurations conf("../../conf/vecwise_engine_log.conf");
|
#if 0
|
||||||
el::Loggers::reconfigureAllLoggers(conf);
|
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");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
el::Loggers::reconfigureAllLoggers(conf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user