From 49b4614b8911e5a54d317e815e18efc0bfbac296 Mon Sep 17 00:00:00 2001 From: groot Date: Mon, 15 Apr 2019 12:35:05 +0800 Subject: [PATCH] add log util Former-commit-id: 4ef6aa4f14c95a9635aa9747b47cb3c3ad002a65 --- cpp/src/CMakeLists.txt | 1 + cpp/src/main.cpp | 8 ++++++- cpp/src/utils/CommonUtil.cpp | 9 ++++---- cpp/src/utils/Log.h | 41 ++++++++++++++++++++++++++++++++++++ cpp/src/utils/LogUtil.cpp | 24 +++++++++++++++++++++ cpp/src/utils/LogUtil.h | 31 +++++++++++++++++++++++++++ cpp/src/utils/SignalUtil.cpp | 1 + 7 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 cpp/src/utils/Log.h create mode 100644 cpp/src/utils/LogUtil.cpp create mode 100644 cpp/src/utils/LogUtil.h diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index 5a623a65be..6698da6387 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -25,6 +25,7 @@ add_executable(vecwise_engine_server ${server_files} ${utils_files} ${wrapper_files} + ${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc ) set(dependency_libs diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 5e3b13a181..03ffd03e07 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -10,9 +10,13 @@ #include #include #include +#include #include "utils/SignalUtil.h" #include "utils/CommonUtil.h" +#include "utils/LogUtil.h" + +INITIALIZE_EASYLOGGINGPP void print_help(const std::string &app_name); @@ -20,7 +24,9 @@ using namespace zilliz::vecwise; int main(int argc, char *argv[]) { - server::CommonUtil::PrintInfo("Vecwise engine server start"); + zilliz::vecwise::server::InitLog(); + + printf("Vecwise engine server start...\n"); // zilliz::lib::gpu::InitMemoryAllocator(); diff --git a/cpp/src/utils/CommonUtil.cpp b/cpp/src/utils/CommonUtil.cpp index da5d011e68..8d991756ad 100644 --- a/cpp/src/utils/CommonUtil.cpp +++ b/cpp/src/utils/CommonUtil.cpp @@ -4,6 +4,7 @@ // Proprietary and confidential. //////////////////////////////////////////////////////////////////////////////// #include "CommonUtil.h" +#include "utils/Log.h" #include #include @@ -31,13 +32,13 @@ namespace server { namespace fs = boost::filesystem; void CommonUtil::PrintInfo(const std::string& info){ -// SERVER_LOG_INFO << info; - std::cout << info << std::endl; + SERVER_LOG_INFO << info; +// std::cout << info << std::endl; } void CommonUtil::PrintError(const std::string& info){ -// SERVER_LOG_ERROR << info; - std::cout << info << std::endl; + SERVER_LOG_ERROR << info; +// std::cout << info << std::endl; } bool CommonUtil::GetSystemMemInfo(unsigned long &totalMem, unsigned long &freeMem) { diff --git a/cpp/src/utils/Log.h b/cpp/src/utils/Log.h new file mode 100644 index 0000000000..5d1ef0a487 --- /dev/null +++ b/cpp/src/utils/Log.h @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include "Error.h" +#include + +namespace zilliz { +namespace vecwise { +namespace server { + +#define SERVER_DOMAIN_NAME "[SERVER] " +#define SERVER_ERROR_TEXT "SERVER Error:" + +#define SERVER_LOG_TRACE LOG(TRACE) << SERVER_DOMAIN_NAME +#define SERVER_LOG_DEBUG LOG(DEBUG) << SERVER_DOMAIN_NAME +#define SERVER_LOG_INFO LOG(INFO) << SERVER_DOMAIN_NAME +#define SERVER_LOG_WARNING LOG(WARNING) << SERVER_DOMAIN_NAME +#define SERVER_LOG_ERROR LOG(ERROR) << SERVER_DOMAIN_NAME +#define SERVER_LOG_FATAL LOG(FATAL) << SERVER_DOMAIN_NAME + +#define SERVER_ERROR(error) \ + ({ \ + SERVER_LOG_ERROR << SERVER_ERROR_TEXT << error; \ + (error); \ + }) + +#define SERVER_CHECK(func) \ + { \ + zilliz::vecwise::server::ServerError error = func; \ + if (error != zilliz::vecwise::server::SERVER_SUCCESS) { \ + return SERVER_ERROR(error); \ + } \ + } \ + +} // namespace sql +} // namespace zilliz +} // namespace server diff --git a/cpp/src/utils/LogUtil.cpp b/cpp/src/utils/LogUtil.cpp new file mode 100644 index 0000000000..6614667cd4 --- /dev/null +++ b/cpp/src/utils/LogUtil.cpp @@ -0,0 +1,24 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +// Unauthorized copying of this file, via any medium is strictly prohibited. +// Proprietary and confidential. +//////////////////////////////////////////////////////////////////////////////// +#include "LogUtil.h" + +#include + +namespace zilliz { +namespace vecwise { +namespace server { + +int32_t InitLog() { + el::Configurations conf("../../conf/vecwise_engine_log.conf"); + el::Loggers::reconfigureAllLoggers(conf); + + return 0; +} + + +} // server +} // vecwise +} // zilliz diff --git a/cpp/src/utils/LogUtil.h b/cpp/src/utils/LogUtil.h new file mode 100644 index 0000000000..189cbb7370 --- /dev/null +++ b/cpp/src/utils/LogUtil.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include +#include + +namespace zilliz { +namespace vecwise { +namespace server { + +int32_t InitLog(); + +inline std::string GetFileName(std::string filename) { + int pos = filename.find_last_of('/'); + return filename.substr(pos + 1); +} + +#define SHOW_LOCATION +#ifdef SHOW_LOCATION +#define LOCATION_INFO "[" << zilliz::sql::server::GetFileName(__FILE__) << ":" << __LINE__ << "] " +#else +#define LOCATION_INFO "" +#endif + +} +} +} diff --git a/cpp/src/utils/SignalUtil.cpp b/cpp/src/utils/SignalUtil.cpp index ef83b6c115..8ffa89d942 100644 --- a/cpp/src/utils/SignalUtil.cpp +++ b/cpp/src/utils/SignalUtil.cpp @@ -6,6 +6,7 @@ #include "SignalUtil.h" #include "CommonUtil.h" #include "server/Server.h" +#include "utils/Log.h" #include #include