From 987ff82e1059c1f8faf9463eb7362652ff433e5f Mon Sep 17 00:00:00 2001 From: jinhai Date: Sun, 14 Apr 2019 19:46:25 +0800 Subject: [PATCH] Add log support and tests Former-commit-id: f946b994174633082110e8d5b26640998e4ed35e --- cpp/conf/vecwise_engine_log.conf | 27 +++++++++++++++++++++++++++ cpp/src/CMakeLists.txt | 8 ++++---- cpp/unittest/CMakeLists.txt | 2 +- cpp/unittest/log/log_tests.cpp | 21 +++++++++++---------- cpp/unittest/vecwise_test.cpp | 3 +++ 5 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 cpp/conf/vecwise_engine_log.conf diff --git a/cpp/conf/vecwise_engine_log.conf b/cpp/conf/vecwise_engine_log.conf new file mode 100644 index 0000000000..ccb9911949 --- /dev/null +++ b/cpp/conf/vecwise_engine_log.conf @@ -0,0 +1,27 @@ +* 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 logs +* 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" \ No newline at end of file diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index e400fb7200..8dcff3def4 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -4,10 +4,10 @@ # Proprietary and confidential. #------------------------------------------------------------------------------- -aux_source_directory(./cache cache_files) -aux_source_directory(./config config_files) -aux_source_directory(./server server_files) -aux_source_directory(./utils utils_files) +aux_source_directory(cache cache_files) +aux_source_directory(config config_files) +aux_source_directory(server server_files) +aux_source_directory(utils utils_files) set(vecwise_engine_src ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp diff --git a/cpp/unittest/CMakeLists.txt b/cpp/unittest/CMakeLists.txt index efa4284d8d..604861f4a6 100644 --- a/cpp/unittest/CMakeLists.txt +++ b/cpp/unittest/CMakeLists.txt @@ -9,7 +9,7 @@ link_directories( ) set(unittest_srcs - ${CMAKE_CURRENT_SOURCE_DIR}/vecwise_test.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/vecwise_test.cpp ${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc) set(unittest_libs gtest_main diff --git a/cpp/unittest/log/log_tests.cpp b/cpp/unittest/log/log_tests.cpp index 31fa26a62f..d4d66cc95a 100644 --- a/cpp/unittest/log/log_tests.cpp +++ b/cpp/unittest/log/log_tests.cpp @@ -4,16 +4,17 @@ // Proprietary and confidential. //////////////////////////////////////////////////////////////////////////////// #include +#include "easylogging++.h" +class LogTest: public testing::Test { +protected: + void SetUp() override { + el::Configurations conf("../../../conf/vecwise_engine_log.conf"); + el::Loggers::reconfigureAllLoggers(conf); + } +}; -TEST(LogTest, INIT_TEST) { - ASSERT_STREQ("A", "A"); -} - -TEST(LogTest, RUN_TEST) { - ASSERT_STREQ("B", "B"); -} - -TEST(LogTest, FINISH_TEST) { - ASSERT_STREQ("C", "C"); +TEST_F(LogTest, TEST) { + EXPECT_FALSE(el::Loggers::hasFlag(el::LoggingFlag::NewLineForContainer)); + EXPECT_FALSE(el::Loggers::hasFlag(el::LoggingFlag::LogDetailedCrashReason)); } \ No newline at end of file diff --git a/cpp/unittest/vecwise_test.cpp b/cpp/unittest/vecwise_test.cpp index d5dfff538c..38f1d15386 100644 --- a/cpp/unittest/vecwise_test.cpp +++ b/cpp/unittest/vecwise_test.cpp @@ -5,6 +5,9 @@ //////////////////////////////////////////////////////////////////////////////// #include #include +#include + +INITIALIZE_EASYLOGGINGPP int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv);