From dfdb5cfbe425303b6e5ce17ace3304d22455a9e6 Mon Sep 17 00:00:00 2001 From: Wang XiangYu Date: Sat, 25 Jul 2020 19:46:34 +0800 Subject: [PATCH] log module (#3017) Signed-off-by: wxyu --- core/src/CMakeLists.txt | 2 + core/src/infra/CMakeLists.txt | 39 ----- core/src/log/CMakeLists.txt | 9 ++ core/src/{utils => log}/Log.cpp | 2 +- core/src/log/Log.h | 135 ++++++++++++++++++ .../src/{utils/LogUtil.cpp => log/LogMgr.cpp} | 45 +----- core/src/{utils/LogUtil.h => log/LogMgr.h} | 25 +--- core/src/server/Server.cpp | 42 +++++- core/src/server/Server.h | 7 + .../server/grpc_impl/GrpcRequestHandler.cpp | 1 - core/src/utils/Log.h | 123 +--------------- core/unittest/CMakeLists.txt | 4 +- core/unittest/ssdb/CMakeLists.txt | 2 +- 13 files changed, 207 insertions(+), 229 deletions(-) delete mode 100644 core/src/infra/CMakeLists.txt create mode 100644 core/src/log/CMakeLists.txt rename core/src/{utils => log}/Log.cpp (98%) create mode 100644 core/src/log/Log.h rename core/src/{utils/LogUtil.cpp => log/LogMgr.cpp} (88%) rename core/src/{utils/LogUtil.h => log/LogMgr.h} (58%) diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index eae01072..b192c944 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -114,6 +114,7 @@ add_subdirectory(tracing) add_subdirectory(query) add_subdirectory(search) add_subdirectory(db) # target milvus_engine +add_subdirectory(log) # **************************** Get&Print Include Directories **************************** get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES ) @@ -128,6 +129,7 @@ set(server_libs config metrics tracing + log oatpp query search diff --git a/core/src/infra/CMakeLists.txt b/core/src/infra/CMakeLists.txt deleted file mode 100644 index f95275aa..00000000 --- a/core/src/infra/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -#------------------------------------------------------------------------------- -# Copyright (C) 2019-2020 Zilliz. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed under the License -# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express -# or implied. See the License for the specific language governing permissions and limitations under the License. -#------------------------------------------------------------------------------- - -# library -set(infra_config_src - ServerConfig.h - config.cpp - ) - -set(infra_src - ${infra_config_src} - ) - -add_library(infra ${infra_src}) - -# unittests -if (BUILD_UNIT_TEST STREQUAL "ON") - - # config_test - add_test( - TARGET config_test - SOURCES - ${infra_config_src} - config_invalid_test.cpp - config_valid_test.cpp - LIBS ${gtest_libraries}) - - # other tests -endif() diff --git a/core/src/log/CMakeLists.txt b/core/src/log/CMakeLists.txt new file mode 100644 index 00000000..12897d8c --- /dev/null +++ b/core/src/log/CMakeLists.txt @@ -0,0 +1,9 @@ +set(log_files + ${MILVUS_ENGINE_SRC}/log/Log.cpp + ${MILVUS_ENGINE_SRC}/log/Log.h + ${MILVUS_ENGINE_SRC}/log/LogMgr.cpp + ${MILVUS_ENGINE_SRC}/log/LogMgr.h + ${thirdparty_easyloggingpp_files} + ) + +add_library(log STATIC ${log_files}) diff --git a/core/src/utils/Log.cpp b/core/src/log/Log.cpp similarity index 98% rename from core/src/utils/Log.cpp rename to core/src/log/Log.cpp index c91b08a8..447d4611 100644 --- a/core/src/utils/Log.cpp +++ b/core/src/log/Log.cpp @@ -9,7 +9,7 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express // or implied. See the License for the specific language governing permissions and limitations under the License. -#include "utils/Log.h" +#include "log/Log.h" #include #include diff --git a/core/src/log/Log.h b/core/src/log/Log.h new file mode 100644 index 00000000..a1ab5d94 --- /dev/null +++ b/core/src/log/Log.h @@ -0,0 +1,135 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#pragma once + +#include + +#include "easyloggingpp/easylogging++.h" + +namespace milvus { + +/* + * Please use LOG_MODULE_LEVEL_C macro in member function of class + * and LOG_MODULE_LEVEL_ macro in other functions. + */ + +///////////////////////////////////////////////////////////////////////////////////////////////// +#define SERVER_MODULE_NAME "SERVER" +#define SERVER_MODULE_CLASS_FUNCTION \ + LogOut("[%s][%s::%s][%s] ", SERVER_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) +#define SERVER_MODULE_FUNCTION LogOut("[%s][%s][%s] ", SERVER_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) + +#define LOG_SERVER_TRACE_C LOG(TRACE) << SERVER_MODULE_CLASS_FUNCTION +#define LOG_SERVER_DEBUG_C LOG(DEBUG) << SERVER_MODULE_CLASS_FUNCTION +#define LOG_SERVER_INFO_C LOG(INFO) << SERVER_MODULE_CLASS_FUNCTION +#define LOG_SERVER_WARNING_C LOG(WARNING) << SERVER_MODULE_CLASS_FUNCTION +#define LOG_SERVER_ERROR_C LOG(ERROR) << SERVER_MODULE_CLASS_FUNCTION +#define LOG_SERVER_FATAL_C LOG(FATAL) << SERVER_MODULE_CLASS_FUNCTION + +#define LOG_SERVER_TRACE_ LOG(TRACE) << SERVER_MODULE_FUNCTION +#define LOG_SERVER_DEBUG_ LOG(DEBUG) << SERVER_MODULE_FUNCTION +#define LOG_SERVER_INFO_ LOG(INFO) << SERVER_MODULE_FUNCTION +#define LOG_SERVER_WARNING_ LOG(WARNING) << SERVER_MODULE_FUNCTION +#define LOG_SERVER_ERROR_ LOG(ERROR) << SERVER_MODULE_FUNCTION +#define LOG_SERVER_FATAL_ LOG(FATAL) << SERVER_MODULE_FUNCTION + +///////////////////////////////////////////////////////////////////////////////////////////////// +#define ENGINE_MODULE_NAME "ENGINE" +#define ENGINE_MODULE_CLASS_FUNCTION \ + LogOut("[%s][%s::%s][%s] ", ENGINE_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) +#define ENGINE_MODULE_FUNCTION LogOut("[%s][%s][%s] ", ENGINE_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) + +#define LOG_ENGINE_TRACE_C LOG(TRACE) << ENGINE_MODULE_CLASS_FUNCTION +#define LOG_ENGINE_DEBUG_C LOG(DEBUG) << ENGINE_MODULE_CLASS_FUNCTION +#define LOG_ENGINE_INFO_C LOG(INFO) << ENGINE_MODULE_CLASS_FUNCTION +#define LOG_ENGINE_WARNING_C LOG(WARNING) << ENGINE_MODULE_CLASS_FUNCTION +#define LOG_ENGINE_ERROR_C LOG(ERROR) << ENGINE_MODULE_CLASS_FUNCTION +#define LOG_ENGINE_FATAL_C LOG(FATAL) << ENGINE_MODULE_CLASS_FUNCTION + +#define LOG_ENGINE_TRACE_ LOG(TRACE) << ENGINE_MODULE_FUNCTION +#define LOG_ENGINE_DEBUG_ LOG(DEBUG) << ENGINE_MODULE_FUNCTION +#define LOG_ENGINE_INFO_ LOG(INFO) << ENGINE_MODULE_FUNCTION +#define LOG_ENGINE_WARNING_ LOG(WARNING) << ENGINE_MODULE_FUNCTION +#define LOG_ENGINE_ERROR_ LOG(ERROR) << ENGINE_MODULE_FUNCTION +#define LOG_ENGINE_FATAL_ LOG(FATAL) << ENGINE_MODULE_FUNCTION + +///////////////////////////////////////////////////////////////////////////////////////////////// +#define WRAPPER_MODULE_NAME "WRAPPER" +#define WRAPPER_MODULE_CLASS_FUNCTION \ + LogOut("[%s][%s::%s][%s] ", WRAPPER_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) +#define WRAPPER_MODULE_FUNCTION LogOut("[%s][%s][%s] ", WRAPPER_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) + +#define LOG_WRAPPER_TRACE_C LOG(TRACE) << WRAPPER_MODULE_CLASS_FUNCTION +#define LOG_WRAPPER_DEBUG_C LOG(DEBUG) << WRAPPER_MODULE_CLASS_FUNCTION +#define LOG_WRAPPER_INFO_C LOG(INFO) << WRAPPER_MODULE_CLASS_FUNCTION +#define LOG_WRAPPER_WARNING_C LOG(WARNING) << WRAPPER_MODULE_CLASS_FUNCTION +#define LOG_WRAPPER_ERROR_C LOG(ERROR) << WRAPPER_MODULE_CLASS_FUNCTION +#define LOG_WRAPPER_FATAL_C LOG(FATAL) << WRAPPER_MODULE_CLASS_FUNCTION + +#define LOG_WRAPPER_TRACE_ LOG(TRACE) << WRAPPER_MODULE_FUNCTION +#define LOG_WRAPPER_DEBUG_ LOG(DEBUG) << WRAPPER_MODULE_FUNCTION +#define LOG_WRAPPER_INFO_ LOG(INFO) << WRAPPER_MODULE_FUNCTION +#define LOG_WRAPPER_WARNING_ LOG(WARNING) << WRAPPER_MODULE_FUNCTION +#define LOG_WRAPPER_ERROR_ LOG(ERROR) << WRAPPER_MODULE_FUNCTION +#define LOG_WRAPPER_FATAL_ LOG(FATAL) << WRAPPER_MODULE_FUNCTION + +///////////////////////////////////////////////////////////////////////////////////////////////// +#define STORAGE_MODULE_NAME "STORAGE" +#define STORAGE_MODULE_CLASS_FUNCTION \ + LogOut("[%s][%s::%s][%s] ", STORAGE_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) +#define STORAGE_MODULE_FUNCTION LogOut("[%s][%s][%s] ", STORAGE_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) + +#define LOG_STORAGE_TRACE_C LOG(TRACE) << STORAGE_MODULE_CLASS_FUNCTION +#define LOG_STORAGE_DEBUG_C LOG(DEBUG) << STORAGE_MODULE_CLASS_FUNCTION +#define LOG_STORAGE_INFO_C LOG(INFO) << STORAGE_MODULE_CLASS_FUNCTION +#define LOG_STORAGE_WARNING_C LOG(WARNING) << STORAGE_MODULE_CLASS_FUNCTION +#define LOG_STORAGE_ERROR_C LOG(ERROR) << STORAGE_MODULE_CLASS_FUNCTION +#define LOG_STORAGE_FATAL_C LOG(FATAL) << STORAGE_MODULE_CLASS_FUNCTION + +#define LOG_STORAGE_TRACE_ LOG(TRACE) << STORAGE_MODULE_FUNCTION +#define LOG_STORAGE_DEBUG_ LOG(DEBUG) << STORAGE_MODULE_FUNCTION +#define LOG_STORAGE_INFO_ LOG(INFO) << STORAGE_MODULE_FUNCTION +#define LOG_STORAGE_WARNING_ LOG(WARNING) << STORAGE_MODULE_FUNCTION +#define LOG_STORAGE_ERROR_ LOG(ERROR) << STORAGE_MODULE_FUNCTION +#define LOG_STORAGE_FATAL_ LOG(FATAL) << STORAGE_MODULE_FUNCTION + +///////////////////////////////////////////////////////////////////////////////////////////////// +#define WAL_MODULE_NAME "WAL" +#define WAL_MODULE_CLASS_FUNCTION \ + LogOut("[%s][%s::%s][%s] ", WAL_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) +#define WAL_MODULE_FUNCTION LogOut("[%s][%s][%s] ", WAL_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) + +#define LOG_WAL_TRACE_C LOG(TRACE) << WAL_MODULE_CLASS_FUNCTION +#define LOG_WAL_DEBUG_C LOG(DEBUG) << WAL_MODULE_CLASS_FUNCTION +#define LOG_WAL_INFO_C LOG(INFO) << WAL_MODULE_CLASS_FUNCTION +#define LOG_WAL_WARNING_C LOG(WARNING) << WAL_MODULE_CLASS_FUNCTION +#define LOG_WAL_ERROR_C LOG(ERROR) << WAL_MODULE_CLASS_FUNCTION +#define LOG_WAL_FATAL_C LOG(FATAL) << WAL_MODULE_CLASS_FUNCTION + +#define LOG_WAL_TRACE_ LOG(TRACE) << WAL_MODULE_FUNCTION +#define LOG_WAL_DEBUG_ LOG(DEBUG) << WAL_MODULE_FUNCTION +#define LOG_WAL_INFO_ LOG(INFO) << WAL_MODULE_FUNCTION +#define LOG_WAL_WARNING_ LOG(WARNING) << WAL_MODULE_FUNCTION +#define LOG_WAL_ERROR_ LOG(ERROR) << WAL_MODULE_FUNCTION +#define LOG_WAL_FATAL_ LOG(FATAL) << WAL_MODULE_FUNCTION + +///////////////////////////////////////////////////////////////////////////////////////////////////// +std::string +LogOut(const char* pattern, ...); + +void +SetThreadName(const std::string& name); + +std::string +GetThreadName(); + +} // namespace milvus diff --git a/core/src/utils/LogUtil.cpp b/core/src/log/LogMgr.cpp similarity index 88% rename from core/src/utils/LogUtil.cpp rename to core/src/log/LogMgr.cpp index 661d75e7..657217a2 100644 --- a/core/src/utils/LogUtil.cpp +++ b/core/src/log/LogMgr.cpp @@ -9,18 +9,16 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express // or implied. See the License for the specific language governing permissions and limitations under the License. -#include "utils/LogUtil.h" - #include #include #include #include -#include #include #include "config/ServerConfig.h" -#include "utils/Log.h" +#include "log/LogMgr.h" +#include "utils/Status.h" namespace milvus { @@ -126,8 +124,8 @@ RolloutHandler(const char* filename, std::size_t size, el::Level level) { } Status -InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_enable, bool error_enable, - bool fatal_enable, const std::string& logs_path, int64_t max_log_file_size, int64_t delete_exceeds) { +LogMgr::InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_enable, bool error_enable, + bool fatal_enable, const std::string& logs_path, int64_t max_log_file_size, int64_t delete_exceeds) { el::Configurations defaultConf; defaultConf.setToDefault(); defaultConf.setGlobally(el::ConfigurationType::Format, "[%datetime][%level]%msg"); @@ -227,39 +225,4 @@ InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_ena return Status::OK(); } -void -LogConfigInFile(const std::string& path) { - // TODO(yhz): Check if file exists - auto node = YAML::LoadFile(path); - YAML::Emitter out; - out << node; - LOG_SERVER_INFO_ << "\n\n" - << std::string(15, '*') << "Config in file" << std::string(15, '*') << "\n\n" - << out.c_str(); -} - -void -LogCpuInfo() { - /*CPU information*/ - std::fstream fcpu("/proc/cpuinfo", std::ios::in); - if (!fcpu.is_open()) { - LOG_SERVER_WARNING_ << "Cannot obtain CPU information. Open file /proc/cpuinfo fail: " << strerror(errno) - << "(errno: " << errno << ")"; - return; - } - std::stringstream cpu_info_ss; - cpu_info_ss << fcpu.rdbuf(); - fcpu.close(); - std::string cpu_info = cpu_info_ss.str(); - - auto processor_pos = cpu_info.rfind("processor"); - if (std::string::npos == processor_pos) { - LOG_SERVER_WARNING_ << "Cannot obtain CPU information. No sub string \'processor\'"; - return; - } - - auto sub_str = cpu_info.substr(processor_pos); - LOG_SERVER_INFO_ << "\n\n" << std::string(15, '*') << "CPU" << std::string(15, '*') << "\n\n" << sub_str; -} - } // namespace milvus diff --git a/core/src/utils/LogUtil.h b/core/src/log/LogMgr.h similarity index 58% rename from core/src/utils/LogUtil.h rename to core/src/log/LogMgr.h index 33f0be07..9bd70794 100644 --- a/core/src/utils/LogUtil.h +++ b/core/src/log/LogMgr.h @@ -19,24 +19,11 @@ namespace milvus { -Status -InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_enable, bool error_enable, - bool fatal_enable, const std::string& logs_path, int64_t max_log_file_size, int64_t delete_exceeds); - -void -RolloutHandler(const char* filename, std::size_t size, el::Level level); - -#define SHOW_LOCATION -#ifdef SHOW_LOCATION -#define LOCATION_INFO "[" << sql::server::GetFileName(__FILE__) << ":" << __LINE__ << "] " -#else -#define LOCATION_INFO "" -#endif - -void -LogConfigInFile(const std::string& path); - -void -LogCpuInfo(); +class LogMgr { + public: + static Status + InitLog(bool trace_enable, bool debug_enable, bool info_enable, bool warning_enable, bool error_enable, + bool fatal_enable, const std::string& logs_path, int64_t max_log_file_size, int64_t delete_exceeds); +}; } // namespace milvus diff --git a/core/src/server/Server.cpp b/core/src/server/Server.cpp index 18a90291..2d1b1f64 100644 --- a/core/src/server/Server.cpp +++ b/core/src/server/Server.cpp @@ -20,6 +20,7 @@ #include "config/ServerConfig.h" #include "index/archive/KnowhereResource.h" +#include "log/LogMgr.h" #include "metrics/Metrics.h" #include "scheduler/SchedInst.h" #include "server/DBWrapper.h" @@ -30,9 +31,9 @@ #include "server/web_impl/WebServer.h" #include "src/version.h" //#include "storage/s3/S3ClientWrapper.h" +#include #include "tracing/TracerUtil.h" #include "utils/Log.h" -#include "utils/LogUtil.h" #include "utils/SignalHandler.h" #include "utils/TimeRecorder.h" @@ -216,8 +217,8 @@ Server::Start() { return Status(SERVER_UNEXPECTED_ERROR, "invalid log level"); } - InitLog(trace_enable, debug_enable, info_enable, warning_enable, error_enable, fatal_enable, logs_path, - max_log_file_size, delete_exceeds); + LogMgr::InitLog(trace_enable, debug_enable, info_enable, warning_enable, error_enable, fatal_enable, + logs_path, max_log_file_size, delete_exceeds); } bool cluster_enable = config.cluster.enable(); @@ -396,5 +397,40 @@ Server::StopService() { engine::KnowhereResource::Finalize(); } +void +Server::LogConfigInFile(const std::string& path) { + // TODO(yhz): Check if file exists + auto node = YAML::LoadFile(path); + YAML::Emitter out; + out << node; + LOG_SERVER_INFO_ << "\n\n" + << std::string(15, '*') << "Config in file" << std::string(15, '*') << "\n\n" + << out.c_str(); +} + +void +Server::LogCpuInfo() { + /*CPU information*/ + std::fstream fcpu("/proc/cpuinfo", std::ios::in); + if (!fcpu.is_open()) { + LOG_SERVER_WARNING_ << "Cannot obtain CPU information. Open file /proc/cpuinfo fail: " << strerror(errno) + << "(errno: " << errno << ")"; + return; + } + std::stringstream cpu_info_ss; + cpu_info_ss << fcpu.rdbuf(); + fcpu.close(); + std::string cpu_info = cpu_info_ss.str(); + + auto processor_pos = cpu_info.rfind("processor"); + if (std::string::npos == processor_pos) { + LOG_SERVER_WARNING_ << "Cannot obtain CPU information. No sub string \'processor\'"; + return; + } + + auto sub_str = cpu_info.substr(processor_pos); + LOG_SERVER_INFO_ << "\n\n" << std::string(15, '*') << "CPU" << std::string(15, '*') << "\n\n" << sub_str; +} + } // namespace server } // namespace milvus diff --git a/core/src/server/Server.h b/core/src/server/Server.h index 616cdb56..6359ab50 100644 --- a/core/src/server/Server.h +++ b/core/src/server/Server.h @@ -46,6 +46,13 @@ class Server { void StopService(); + private: + static void + LogConfigInFile(const std::string& path); + + static void + LogCpuInfo(); + private: int64_t daemonized_ = 0; int pid_fd_ = -1; diff --git a/core/src/server/grpc_impl/GrpcRequestHandler.cpp b/core/src/server/grpc_impl/GrpcRequestHandler.cpp index 3fc892c7..3ada636a 100644 --- a/core/src/server/grpc_impl/GrpcRequestHandler.cpp +++ b/core/src/server/grpc_impl/GrpcRequestHandler.cpp @@ -25,7 +25,6 @@ #include "tracing/TextMapCarrier.h" #include "tracing/TracerUtil.h" #include "utils/Log.h" -#include "utils/LogUtil.h" namespace milvus { namespace server { diff --git a/core/src/utils/Log.h b/core/src/utils/Log.h index a1ab5d94..f2a25d7d 100644 --- a/core/src/utils/Log.h +++ b/core/src/utils/Log.h @@ -11,125 +11,4 @@ #pragma once -#include - -#include "easyloggingpp/easylogging++.h" - -namespace milvus { - -/* - * Please use LOG_MODULE_LEVEL_C macro in member function of class - * and LOG_MODULE_LEVEL_ macro in other functions. - */ - -///////////////////////////////////////////////////////////////////////////////////////////////// -#define SERVER_MODULE_NAME "SERVER" -#define SERVER_MODULE_CLASS_FUNCTION \ - LogOut("[%s][%s::%s][%s] ", SERVER_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) -#define SERVER_MODULE_FUNCTION LogOut("[%s][%s][%s] ", SERVER_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) - -#define LOG_SERVER_TRACE_C LOG(TRACE) << SERVER_MODULE_CLASS_FUNCTION -#define LOG_SERVER_DEBUG_C LOG(DEBUG) << SERVER_MODULE_CLASS_FUNCTION -#define LOG_SERVER_INFO_C LOG(INFO) << SERVER_MODULE_CLASS_FUNCTION -#define LOG_SERVER_WARNING_C LOG(WARNING) << SERVER_MODULE_CLASS_FUNCTION -#define LOG_SERVER_ERROR_C LOG(ERROR) << SERVER_MODULE_CLASS_FUNCTION -#define LOG_SERVER_FATAL_C LOG(FATAL) << SERVER_MODULE_CLASS_FUNCTION - -#define LOG_SERVER_TRACE_ LOG(TRACE) << SERVER_MODULE_FUNCTION -#define LOG_SERVER_DEBUG_ LOG(DEBUG) << SERVER_MODULE_FUNCTION -#define LOG_SERVER_INFO_ LOG(INFO) << SERVER_MODULE_FUNCTION -#define LOG_SERVER_WARNING_ LOG(WARNING) << SERVER_MODULE_FUNCTION -#define LOG_SERVER_ERROR_ LOG(ERROR) << SERVER_MODULE_FUNCTION -#define LOG_SERVER_FATAL_ LOG(FATAL) << SERVER_MODULE_FUNCTION - -///////////////////////////////////////////////////////////////////////////////////////////////// -#define ENGINE_MODULE_NAME "ENGINE" -#define ENGINE_MODULE_CLASS_FUNCTION \ - LogOut("[%s][%s::%s][%s] ", ENGINE_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) -#define ENGINE_MODULE_FUNCTION LogOut("[%s][%s][%s] ", ENGINE_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) - -#define LOG_ENGINE_TRACE_C LOG(TRACE) << ENGINE_MODULE_CLASS_FUNCTION -#define LOG_ENGINE_DEBUG_C LOG(DEBUG) << ENGINE_MODULE_CLASS_FUNCTION -#define LOG_ENGINE_INFO_C LOG(INFO) << ENGINE_MODULE_CLASS_FUNCTION -#define LOG_ENGINE_WARNING_C LOG(WARNING) << ENGINE_MODULE_CLASS_FUNCTION -#define LOG_ENGINE_ERROR_C LOG(ERROR) << ENGINE_MODULE_CLASS_FUNCTION -#define LOG_ENGINE_FATAL_C LOG(FATAL) << ENGINE_MODULE_CLASS_FUNCTION - -#define LOG_ENGINE_TRACE_ LOG(TRACE) << ENGINE_MODULE_FUNCTION -#define LOG_ENGINE_DEBUG_ LOG(DEBUG) << ENGINE_MODULE_FUNCTION -#define LOG_ENGINE_INFO_ LOG(INFO) << ENGINE_MODULE_FUNCTION -#define LOG_ENGINE_WARNING_ LOG(WARNING) << ENGINE_MODULE_FUNCTION -#define LOG_ENGINE_ERROR_ LOG(ERROR) << ENGINE_MODULE_FUNCTION -#define LOG_ENGINE_FATAL_ LOG(FATAL) << ENGINE_MODULE_FUNCTION - -///////////////////////////////////////////////////////////////////////////////////////////////// -#define WRAPPER_MODULE_NAME "WRAPPER" -#define WRAPPER_MODULE_CLASS_FUNCTION \ - LogOut("[%s][%s::%s][%s] ", WRAPPER_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) -#define WRAPPER_MODULE_FUNCTION LogOut("[%s][%s][%s] ", WRAPPER_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) - -#define LOG_WRAPPER_TRACE_C LOG(TRACE) << WRAPPER_MODULE_CLASS_FUNCTION -#define LOG_WRAPPER_DEBUG_C LOG(DEBUG) << WRAPPER_MODULE_CLASS_FUNCTION -#define LOG_WRAPPER_INFO_C LOG(INFO) << WRAPPER_MODULE_CLASS_FUNCTION -#define LOG_WRAPPER_WARNING_C LOG(WARNING) << WRAPPER_MODULE_CLASS_FUNCTION -#define LOG_WRAPPER_ERROR_C LOG(ERROR) << WRAPPER_MODULE_CLASS_FUNCTION -#define LOG_WRAPPER_FATAL_C LOG(FATAL) << WRAPPER_MODULE_CLASS_FUNCTION - -#define LOG_WRAPPER_TRACE_ LOG(TRACE) << WRAPPER_MODULE_FUNCTION -#define LOG_WRAPPER_DEBUG_ LOG(DEBUG) << WRAPPER_MODULE_FUNCTION -#define LOG_WRAPPER_INFO_ LOG(INFO) << WRAPPER_MODULE_FUNCTION -#define LOG_WRAPPER_WARNING_ LOG(WARNING) << WRAPPER_MODULE_FUNCTION -#define LOG_WRAPPER_ERROR_ LOG(ERROR) << WRAPPER_MODULE_FUNCTION -#define LOG_WRAPPER_FATAL_ LOG(FATAL) << WRAPPER_MODULE_FUNCTION - -///////////////////////////////////////////////////////////////////////////////////////////////// -#define STORAGE_MODULE_NAME "STORAGE" -#define STORAGE_MODULE_CLASS_FUNCTION \ - LogOut("[%s][%s::%s][%s] ", STORAGE_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) -#define STORAGE_MODULE_FUNCTION LogOut("[%s][%s][%s] ", STORAGE_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) - -#define LOG_STORAGE_TRACE_C LOG(TRACE) << STORAGE_MODULE_CLASS_FUNCTION -#define LOG_STORAGE_DEBUG_C LOG(DEBUG) << STORAGE_MODULE_CLASS_FUNCTION -#define LOG_STORAGE_INFO_C LOG(INFO) << STORAGE_MODULE_CLASS_FUNCTION -#define LOG_STORAGE_WARNING_C LOG(WARNING) << STORAGE_MODULE_CLASS_FUNCTION -#define LOG_STORAGE_ERROR_C LOG(ERROR) << STORAGE_MODULE_CLASS_FUNCTION -#define LOG_STORAGE_FATAL_C LOG(FATAL) << STORAGE_MODULE_CLASS_FUNCTION - -#define LOG_STORAGE_TRACE_ LOG(TRACE) << STORAGE_MODULE_FUNCTION -#define LOG_STORAGE_DEBUG_ LOG(DEBUG) << STORAGE_MODULE_FUNCTION -#define LOG_STORAGE_INFO_ LOG(INFO) << STORAGE_MODULE_FUNCTION -#define LOG_STORAGE_WARNING_ LOG(WARNING) << STORAGE_MODULE_FUNCTION -#define LOG_STORAGE_ERROR_ LOG(ERROR) << STORAGE_MODULE_FUNCTION -#define LOG_STORAGE_FATAL_ LOG(FATAL) << STORAGE_MODULE_FUNCTION - -///////////////////////////////////////////////////////////////////////////////////////////////// -#define WAL_MODULE_NAME "WAL" -#define WAL_MODULE_CLASS_FUNCTION \ - LogOut("[%s][%s::%s][%s] ", WAL_MODULE_NAME, (typeid(*this).name()), __FUNCTION__, GetThreadName().c_str()) -#define WAL_MODULE_FUNCTION LogOut("[%s][%s][%s] ", WAL_MODULE_NAME, __FUNCTION__, GetThreadName().c_str()) - -#define LOG_WAL_TRACE_C LOG(TRACE) << WAL_MODULE_CLASS_FUNCTION -#define LOG_WAL_DEBUG_C LOG(DEBUG) << WAL_MODULE_CLASS_FUNCTION -#define LOG_WAL_INFO_C LOG(INFO) << WAL_MODULE_CLASS_FUNCTION -#define LOG_WAL_WARNING_C LOG(WARNING) << WAL_MODULE_CLASS_FUNCTION -#define LOG_WAL_ERROR_C LOG(ERROR) << WAL_MODULE_CLASS_FUNCTION -#define LOG_WAL_FATAL_C LOG(FATAL) << WAL_MODULE_CLASS_FUNCTION - -#define LOG_WAL_TRACE_ LOG(TRACE) << WAL_MODULE_FUNCTION -#define LOG_WAL_DEBUG_ LOG(DEBUG) << WAL_MODULE_FUNCTION -#define LOG_WAL_INFO_ LOG(INFO) << WAL_MODULE_FUNCTION -#define LOG_WAL_WARNING_ LOG(WARNING) << WAL_MODULE_FUNCTION -#define LOG_WAL_ERROR_ LOG(ERROR) << WAL_MODULE_FUNCTION -#define LOG_WAL_FATAL_ LOG(FATAL) << WAL_MODULE_FUNCTION - -///////////////////////////////////////////////////////////////////////////////////////////////////// -std::string -LogOut(const char* pattern, ...); - -void -SetThreadName(const std::string& name); - -std::string -GetThreadName(); - -} // namespace milvus +#include "log/Log.h" diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index c75ffb7f..e0d43565 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -151,8 +151,8 @@ set(common_files ) set(log_files - ${MILVUS_ENGINE_SRC}/utils/Log.cpp - ${MILVUS_ENGINE_SRC}/utils/LogUtil.cpp + ${MILVUS_ENGINE_SRC}/log/Log.cpp + ${MILVUS_ENGINE_SRC}/log/LogMgr.cpp ${MILVUS_THIRDPARTY_SRC}/easyloggingpp/easylogging++.cc ) diff --git a/core/unittest/ssdb/CMakeLists.txt b/core/unittest/ssdb/CMakeLists.txt index 2f54f9fb..7b8b938e 100644 --- a/core/unittest/ssdb/CMakeLists.txt +++ b/core/unittest/ssdb/CMakeLists.txt @@ -24,7 +24,6 @@ set(test_files add_executable(test_ssdb ${common_files} - ${log_files} ${cache_files} ${codecs_files} ${codecs_default_files} @@ -42,6 +41,7 @@ add_executable(test_ssdb ${db_snapshot_files} # ${grpc_server_files} # ${grpc_service_files} + ${log_files} ${metrics_files} ${query_files} ${segment_files} -- GitLab