mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
Merge branch 'MS-119_log_file_question' into 'branch-0.4.0'
MS-119 The problem of combining the log files Closes MS-119 See merge request megasearch/milvus!521 Former-commit-id: 0be6356af88683292e04f57e63915181b7d62147
This commit is contained in:
commit
5286d988dd
@ -30,6 +30,7 @@ Please mark all change in change log and use the ticket from JIRA.
|
||||
- MS-493 - Knowhere unittest crash
|
||||
- MS-453 - GPU search error when nprobe set more than 1024
|
||||
- MS-510 - unittest out of memory and crashed
|
||||
- MS-119 - The problem of combining the log files
|
||||
|
||||
## Improvement
|
||||
- MS-327 - Clean code for milvus
|
||||
|
||||
@ -9,11 +9,70 @@
|
||||
#include <easylogging++.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <string>
|
||||
#include <libgen.h>
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
|
||||
int32_t InitLog(const std::string& log_config_file) {
|
||||
namespace {
|
||||
static int global_idx = 0;
|
||||
static int debug_idx = 0;
|
||||
static int warning_idx = 0;
|
||||
static int trace_idx = 0;
|
||||
static int error_idx = 0;
|
||||
static int fatal_idx = 0;
|
||||
}
|
||||
|
||||
// TODO(yzb) : change the easylogging library to get the log level from parameter rather than filename
|
||||
void rolloutHandler(const char *filename, std::size_t size) {
|
||||
char *dirc = strdup(filename);
|
||||
char *basec = strdup(filename);
|
||||
char *dir = dirname(dirc);
|
||||
char *base = basename(basec);
|
||||
|
||||
std::string s(base);
|
||||
std::stringstream ss;
|
||||
std::string
|
||||
list[] = {"\\", " ", "\'", "\"", "*", "\?", "{", "}", ";", "<", ">", "|", "^", "&", "$", "#", "!", "`", "~"};
|
||||
std::string::size_type position;
|
||||
for (auto substr : list) {
|
||||
position = 0;
|
||||
while ((position = s.find_first_of(substr, position)) != std::string::npos) {
|
||||
s.insert(position, "\\");
|
||||
position += 2;
|
||||
}
|
||||
}
|
||||
int ret;
|
||||
std::string m(std::string(dir) + "/" + s);
|
||||
s = m;
|
||||
if ((position = s.find("global")) != std::string::npos) {
|
||||
s.append("." + std::to_string(++global_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
} else if ((position = s.find("debug")) != std::string::npos) {
|
||||
s.append("." + std::to_string(++debug_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
} else if ((position = s.find("warning")) != std::string::npos) {
|
||||
s.append("." + std::to_string(++warning_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
} else if ((position = s.find("trace")) != std::string::npos) {
|
||||
s.append("." + std::to_string(++trace_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
} else if ((position = s.find("error")) != std::string::npos) {
|
||||
s.append("." + std::to_string(++error_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
} else if ((position = s.find("fatal")) != std::string::npos) {
|
||||
s.append("." + std::to_string(++fatal_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
} else {
|
||||
s.append("." + std::to_string(++global_idx));
|
||||
ret = rename(m.c_str(), s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InitLog(const std::string &log_config_file) {
|
||||
#if 0
|
||||
ServerConfig &config = ServerConfig::GetInstance();
|
||||
ConfigNode log_config = config.GetConfig(CONFIG_LOG);
|
||||
@ -50,8 +109,10 @@ int32_t InitLog(const std::string& log_config_file) {
|
||||
#else
|
||||
el::Configurations conf(log_config_file);
|
||||
#endif
|
||||
|
||||
el::Loggers::reconfigureAllLoggers(conf);
|
||||
|
||||
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
|
||||
el::Helpers::installPreRollOutCallback(rolloutHandler);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -11,9 +11,7 @@
|
||||
namespace zilliz {
|
||||
namespace milvus {
|
||||
namespace server {
|
||||
|
||||
int32_t InitLog(const std::string& log_config_file);
|
||||
|
||||
inline std::string GetFileName(std::string filename) {
|
||||
int pos = filename.find_last_of('/');
|
||||
return filename.substr(pos + 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user