mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 18:38:44 +08:00
refine log code
Former-commit-id: 96584eb602bacf90d6482cdef60608fa31f488f1
This commit is contained in:
parent
18994f2aa9
commit
5a8b70b779
@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
#include "ConfigNode.h"
|
||||
#include "utils/Error.h"
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -177,18 +177,18 @@ void ConfigNode::ClearSequences() {
|
||||
void
|
||||
ConfigNode::PrintAll(const std::string& prefix) const {
|
||||
for(auto& elem : config_) {
|
||||
CommonUtil::PrintInfo(prefix + elem.first + ": " + elem.second);
|
||||
SERVER_LOG_INFO << prefix << elem.first + ": " << elem.second;
|
||||
}
|
||||
|
||||
for(auto& elem : sequences_) {
|
||||
CommonUtil::PrintInfo(prefix + elem.first + ": ");
|
||||
SERVER_LOG_INFO << prefix << elem.first << ": ";
|
||||
for(auto& str : elem.second) {
|
||||
CommonUtil::PrintInfo(prefix + " - " + str);
|
||||
SERVER_LOG_INFO << prefix << " - " << str;
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& elem : children_) {
|
||||
CommonUtil::PrintInfo(prefix + elem.first + ": ");
|
||||
SERVER_LOG_INFO << prefix << elem.first << ": ";
|
||||
elem.second.PrintAll(prefix + " ");
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
#include "YamlConfigMgr.h"
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
@ -16,7 +16,7 @@ ServerError YamlConfigMgr::LoadConfigFile(const std::string &filename) {
|
||||
struct stat directoryStat;
|
||||
int statOK = stat(filename.c_str(), &directoryStat);
|
||||
if (statOK != 0) {
|
||||
CommonUtil::PrintError("File not found: " + filename);
|
||||
SERVER_LOG_ERROR << "File not found: " << filename;
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ ServerError YamlConfigMgr::LoadConfigFile(const std::string &filename) {
|
||||
LoadConfigNode(node_, config_);
|
||||
}
|
||||
catch (YAML::Exception& e) {
|
||||
CommonUtil::PrintError("Failed to load config file: " + std::string(e.what ()));
|
||||
SERVER_LOG_ERROR << "Failed to load config file: " << std::string(e.what ());
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ ServerError YamlConfigMgr::LoadConfigFile(const std::string &filename) {
|
||||
}
|
||||
|
||||
void YamlConfigMgr::Print() const {
|
||||
CommonUtil::PrintInfo("System config content:");
|
||||
SERVER_LOG_INFO << "System config content:";
|
||||
config_.PrintAll();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "Server.h"
|
||||
#include "ServerConfig.h"
|
||||
#include "ServiceWrapper.h"
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "utils/Log.h"
|
||||
#include "utils/SignalUtil.h"
|
||||
#include "utils/TimeRecorder.h"
|
||||
#include "utils/LogUtil.h"
|
||||
@ -50,11 +50,11 @@ Server::Daemonize() {
|
||||
return;
|
||||
}
|
||||
|
||||
CommonUtil::PrintInfo("Vecwise server run in daemonize mode");
|
||||
SERVER_LOG_INFO << "Vecwise server run in daemonize mode";
|
||||
|
||||
// std::string log_path(GetLogDirFullPath());
|
||||
// log_path += "zdb_server.(INFO/WARNNING/ERROR/CRITICAL)";
|
||||
// CommonUtil::PrintInfo("Log will be exported to: " + log_path);
|
||||
// SERVER_LOG_INFO << "Log will be exported to: " + log_path);
|
||||
|
||||
pid_t pid = 0;
|
||||
|
||||
@ -106,7 +106,7 @@ Server::Daemonize() {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
CommonUtil::PrintInfo("Redirect stdin/stdout/stderr to /dev/null");
|
||||
SERVER_LOG_INFO << "Redirect stdin/stdout/stderr to /dev/null";
|
||||
|
||||
// Redirect stdin/stdout/stderr to /dev/null
|
||||
stdin = fopen("/dev/null", "r");
|
||||
@ -116,11 +116,11 @@ Server::Daemonize() {
|
||||
if (!pid_filename_.empty()) {
|
||||
pid_fd = open(pid_filename_.c_str(), O_RDWR | O_CREAT, 0640);
|
||||
if (pid_fd < 0) {
|
||||
CommonUtil::PrintInfo("Can't open filename: " + pid_filename_ + ", Error: " + strerror(errno));
|
||||
SERVER_LOG_INFO << "Can't open filename: " + pid_filename_ + ", Error: " + strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (lockf(pid_fd, F_TLOCK, 0) < 0) {
|
||||
CommonUtil::PrintInfo("Can't lock filename: " + pid_filename_ + ", Error: " + strerror(errno));
|
||||
SERVER_LOG_INFO << "Can't lock filename: " + pid_filename_ + ", Error: " + strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -159,14 +159,12 @@ Server::Start() {
|
||||
signal(SIGHUP, SignalUtil::HandleSignal);
|
||||
signal(SIGTERM, SignalUtil::HandleSignal);
|
||||
|
||||
CommonUtil::PrintInfo("Vecwise server is running...");
|
||||
SERVER_LOG_INFO << "Vecwise server is running...";
|
||||
StartService();
|
||||
|
||||
} catch(std::exception& ex){
|
||||
std::string info = "Vecwise server encounter exception: " + std::string(ex.what());
|
||||
CommonUtil::PrintError(info);
|
||||
|
||||
CommonUtil::PrintInfo("Is another server instance running?");
|
||||
SERVER_LOG_ERROR << "Vecwise server encounter exception: " << std::string(ex.what())
|
||||
<< "Is another server instance running?";
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
@ -177,7 +175,7 @@ Server::Start() {
|
||||
|
||||
void
|
||||
Server::Stop() {
|
||||
CommonUtil::PrintInfo("Vecwise server will be closed");
|
||||
SERVER_LOG_INFO << "Vecwise server will be closed";
|
||||
|
||||
// Unlock and close lockfile
|
||||
if (pid_fd != -1) {
|
||||
@ -204,7 +202,7 @@ Server::Stop() {
|
||||
StopService();
|
||||
|
||||
|
||||
CommonUtil::PrintInfo("Vecwise server closed");
|
||||
SERVER_LOG_INFO << "Vecwise server closed";
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "ServiceWrapper.h"
|
||||
#include "ServerConfig.h"
|
||||
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
#include "thrift/gen-cpp/VecService.h"
|
||||
#include "thrift/gen-cpp/VectorService_types.h"
|
||||
@ -40,7 +40,7 @@ public:
|
||||
|
||||
void dummy() {
|
||||
// Your implementation goes here
|
||||
printf("dummy\n");
|
||||
printf("dummy() called\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +127,7 @@ void ServiceWrapper::StartService() {
|
||||
} else if(protocol == "json") {
|
||||
protocolFactory.reset(new TJSONProtocolFactory());
|
||||
} else {
|
||||
CommonUtil::PrintError("Service protocol: " + protocol + " is not supported currently");
|
||||
SERVER_LOG_INFO << "Service protocol: " << protocol << " is not supported currently";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ void ServiceWrapper::StartService() {
|
||||
s_server.reset(new TThreadPoolServer(processor, serverTransport, transportFactory, protocolFactory, threadManager));
|
||||
s_server->serve();
|
||||
} else {
|
||||
CommonUtil::PrintError("Service mode: " + mode + " is not supported currently");
|
||||
SERVER_LOG_INFO << "Service mode: " << mode << " is not supported currently";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -31,16 +31,6 @@ namespace server {
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
void CommonUtil::PrintInfo(const std::string& info){
|
||||
SERVER_LOG_INFO << info;
|
||||
std::cout << "Info:" << info << std::endl;
|
||||
}
|
||||
|
||||
void CommonUtil::PrintError(const std::string& info){
|
||||
SERVER_LOG_ERROR << info;
|
||||
std::cout << "Error:" << info << std::endl;
|
||||
}
|
||||
|
||||
bool CommonUtil::GetSystemMemInfo(unsigned long &totalMem, unsigned long &freeMem) {
|
||||
struct sysinfo info;
|
||||
int ret = sysinfo(&info);
|
||||
|
@ -15,9 +15,6 @@ namespace server {
|
||||
|
||||
class CommonUtil {
|
||||
public:
|
||||
static void PrintInfo(const std::string& info);
|
||||
static void PrintError(const std::string& info);
|
||||
|
||||
static bool GetSystemMemInfo(unsigned long &totalMem, unsigned long &freeMem);
|
||||
static bool GetSystemAvailableThreads(unsigned int &threadCnt);
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "SignalUtil.h"
|
||||
#include "CommonUtil.h"
|
||||
#include "server/Server.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
@ -16,7 +15,7 @@ namespace vecwise {
|
||||
namespace server {
|
||||
|
||||
void SignalUtil::HandleSignal(int signum){
|
||||
CommonUtil::PrintInfo("Server received signal:" + std::to_string(signum));
|
||||
SERVER_LOG_INFO << "Server received signal:" << std::to_string(signum);
|
||||
|
||||
switch(signum){
|
||||
case SIGINT:
|
||||
@ -33,7 +32,7 @@ void SignalUtil::HandleSignal(int signum){
|
||||
info += std::to_string(signum);
|
||||
// SendSignalMessage(signum, info);
|
||||
|
||||
CommonUtil::PrintInfo(info);
|
||||
SERVER_LOG_INFO << info;
|
||||
|
||||
server::Server* server_ptr = server::Server::Instance();
|
||||
server_ptr->Stop();
|
||||
@ -44,7 +43,7 @@ void SignalUtil::HandleSignal(int signum){
|
||||
}
|
||||
|
||||
void SignalUtil::PrintStacktrace() {
|
||||
CommonUtil::PrintInfo("Call stack:");
|
||||
SERVER_LOG_INFO << "Call stack:";
|
||||
|
||||
const int size = 32;
|
||||
void* array[size];
|
||||
@ -52,7 +51,7 @@ void SignalUtil::PrintStacktrace() {
|
||||
char ** stacktrace = backtrace_symbols(array, stack_num);
|
||||
for (int i = 0; i < stack_num; ++i) {
|
||||
std::string info = stacktrace[i];
|
||||
CommonUtil::PrintInfo(info);
|
||||
SERVER_LOG_INFO << info;
|
||||
}
|
||||
free(stacktrace);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "TimeRecorder.h"
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
|
||||
namespace zilliz {
|
||||
@ -87,31 +87,31 @@ TimeRecorder::PrintTimeRecord(const std::string &msg, double span) {
|
||||
|
||||
switch (log_level_) {
|
||||
case 0: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_TRACE << strLog;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_DEBUG << strLog;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_INFO << strLog;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_WARNING << strLog;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_ERROR << strLog;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_FATAL << strLog;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
CommonUtil::PrintInfo(strLog);
|
||||
SERVER_LOG_INFO << strLog;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ main(int argc, char *argv[]) {
|
||||
char *config_filename_ptr = strdup(optarg);
|
||||
config_filename = config_filename_ptr;
|
||||
free(config_filename_ptr);
|
||||
printf("Loading configuration from: %s\n", config_filename.c_str());
|
||||
break;
|
||||
}
|
||||
case 'h':
|
||||
|
@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
#include "ClientApp.h"
|
||||
#include "server/ServerConfig.h"
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
@ -36,13 +36,15 @@ void ClientApp::Run(const std::string &config_file) {
|
||||
server::ServerConfig& config = server::ServerConfig::GetInstance();
|
||||
config.LoadConfigFile(config_file);
|
||||
|
||||
CLIENT_LOG_INFO << "Load config file:" << config_file;
|
||||
|
||||
server::ConfigNode server_config = config.GetConfig(server::CONFIG_SERVER);
|
||||
std::string address = server_config.GetValue(server::CONFIG_SERVER_ADDRESS, "127.0.0.1");
|
||||
int32_t port = server_config.GetInt32Value(server::CONFIG_SERVER_PORT, 33001);
|
||||
std::string protocol = server_config.GetValue(server::CONFIG_SERVER_PROTOCOL, "binary");
|
||||
std::string mode = server_config.GetValue(server::CONFIG_SERVER_MODE, "thread_pool");
|
||||
|
||||
|
||||
CLIENT_LOG_INFO << "Connect to server: " << address << ":" << std::to_string(port);
|
||||
::apache::thrift::stdcxx::shared_ptr<TSocket> socket_ptr(new ::apache::thrift::transport::TSocket(address, port));
|
||||
::apache::thrift::stdcxx::shared_ptr<TTransport> transport_ptr(new TBufferedTransport(socket_ptr));
|
||||
::apache::thrift::stdcxx::shared_ptr<TProtocol> protocol_ptr;
|
||||
@ -51,7 +53,7 @@ void ClientApp::Run(const std::string &config_file) {
|
||||
} else if(protocol == "json") {
|
||||
protocol_ptr.reset(new TJSONProtocol(transport_ptr));
|
||||
} else {
|
||||
server::CommonUtil::PrintError("Service protocol: " + protocol + " is not supported currently");
|
||||
CLIENT_LOG_ERROR << "Service protocol: " << protocol << " is not supported currently";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -70,6 +72,8 @@ void ClientApp::Run(const std::string &config_file) {
|
||||
}
|
||||
|
||||
transport_ptr->close();
|
||||
|
||||
CLIENT_LOG_INFO << "Test finished";
|
||||
}
|
||||
|
||||
}
|
||||
|
26
cpp/test_client/src/Log.h
Normal file
26
cpp/test_client/src/Log.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
* Proprietary and confidential.
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <easylogging++.h>
|
||||
|
||||
namespace zilliz {
|
||||
namespace vecwise {
|
||||
namespace client {
|
||||
|
||||
#define CLIENT_DOMAIN_NAME "[CLIENT] "
|
||||
#define CLIENT_ERROR_TEXT "CLIENT Error:"
|
||||
|
||||
#define CLIENT_LOG_TRACE LOG(TRACE) << CLIENT_DOMAIN_NAME
|
||||
#define CLIENT_LOG_DEBUG LOG(DEBUG) << CLIENT_DOMAIN_NAME
|
||||
#define CLIENT_LOG_INFO LOG(INFO) << CLIENT_DOMAIN_NAME
|
||||
#define CLIENT_LOG_WARNING LOG(WARNING) << CLIENT_DOMAIN_NAME
|
||||
#define CLIENT_LOG_ERROR LOG(ERROR) << CLIENT_DOMAIN_NAME
|
||||
#define CLIENT_LOG_FATAL LOG(FATAL) << CLIENT_DOMAIN_NAME
|
||||
|
||||
} // namespace sql
|
||||
} // namespace zilliz
|
||||
} // namespace server
|
Loading…
Reference in New Issue
Block a user