From 09c908ab83298abea32b3d9fc4c1506f36584afe Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Tue, 30 Jul 2024 01:14:09 +0800 Subject: [PATCH] feat(logging): Use spdlog to replace simple_logger and screen_logger --- .clang-tidy | 2 +- .licenserc.yaml | 3 - build_tools/clang_tidy.py | 3 +- cmake_modules/BaseFunctions.cmake | 6 + src/aio/test/config.ini | 1 - src/base/test/config.ini | 2 - src/block_service/test/config-test.ini | 1 - src/client/test/config.ini | 2 - src/client_lib/pegasus_client_impl.cpp | 1 - src/common/test/config-test.ini | 2 - src/failure_detector/test/config-test.ini | 1 - .../test/config-whitelist-test-failed.ini | 1 - .../test/config-whitelist-test.ini | 1 - src/geo/bench/config.ini | 2 - src/geo/test/config.ini | 2 - src/gutil/test/map_util_unittest.cpp | 5 +- src/http/pprof_http_service.cpp | 14 +- src/http/test/config-test.ini | 1 - .../duplication/meta_duplication_service.cpp | 6 +- src/meta/test/config-test.ini | 2 - src/meta/test/dump_file.cpp | 7 +- src/meta/test/meta_state/config-test.ini | 2 - src/nfs/test/config.ini | 1 - src/nfs/test/nfs_test_file1 | 2 - src/nfs/test/nfs_test_file2 | 3 - src/redis_protocol/proxy/config.ini | 2 - src/redis_protocol/proxy_ut/config.ini | 2 - src/replica/bulk_load/test/config-test.ini | 2 - src/replica/replica_2pc.cpp | 11 +- src/replica/split/test/config-test.ini | 2 - src/replica/storage/simple_kv/config.ini | 2 - .../storage/simple_kv/test/case-000.ini | 1 - .../storage/simple_kv/test/case-001.ini | 1 - .../storage/simple_kv/test/case-002.ini | 1 - .../storage/simple_kv/test/case-003.ini | 1 - .../storage/simple_kv/test/case-004.ini | 1 - .../storage/simple_kv/test/case-005.ini | 1 - .../storage/simple_kv/test/case-006.ini | 1 - .../storage/simple_kv/test/case-100.ini | 1 - .../storage/simple_kv/test/case-101.ini | 1 - .../storage/simple_kv/test/case-102.ini | 1 - .../storage/simple_kv/test/case-103.ini | 1 - .../storage/simple_kv/test/case-104.ini | 1 - .../storage/simple_kv/test/case-105.ini | 1 - .../storage/simple_kv/test/case-106.ini | 1 - .../storage/simple_kv/test/case-107.ini | 1 - .../storage/simple_kv/test/case-108.ini | 1 - .../storage/simple_kv/test/case-109.ini | 1 - .../storage/simple_kv/test/case-200.ini | 1 - .../storage/simple_kv/test/case-201.ini | 1 - .../storage/simple_kv/test/case-202-0.ini | 1 - .../storage/simple_kv/test/case-202-1.ini | 1 - .../storage/simple_kv/test/case-203-0.ini | 1 - .../storage/simple_kv/test/case-204.ini | 1 - .../storage/simple_kv/test/case-205.ini | 1 - .../storage/simple_kv/test/case-206.ini | 1 - .../storage/simple_kv/test/case-207.ini | 1 - .../storage/simple_kv/test/case-208.ini | 1 - .../storage/simple_kv/test/case-209.ini | 1 - .../storage/simple_kv/test/case-210.ini | 1 - .../storage/simple_kv/test/case-211.ini | 1 - .../storage/simple_kv/test/case-212.ini | 1 - .../storage/simple_kv/test/case-213.ini | 1 - .../storage/simple_kv/test/case-214.ini | 1 - .../storage/simple_kv/test/case-215.ini | 1 - .../storage/simple_kv/test/case-216.ini | 1 - .../storage/simple_kv/test/case-300-0.ini | 1 - .../storage/simple_kv/test/case-300-1.ini | 1 - .../storage/simple_kv/test/case-300-2.ini | 1 - .../storage/simple_kv/test/case-301.ini | 1 - .../storage/simple_kv/test/case-302.ini | 1 - .../storage/simple_kv/test/case-303.ini | 1 - .../storage/simple_kv/test/case-304.ini | 1 - .../storage/simple_kv/test/case-305.ini | 1 - .../storage/simple_kv/test/case-306.ini | 1 - .../storage/simple_kv/test/case-307.ini | 1 - .../storage/simple_kv/test/case-400.ini | 1 - .../storage/simple_kv/test/case-401.ini | 1 - .../storage/simple_kv/test/case-402.ini | 1 - .../storage/simple_kv/test/case-600.ini | 1 - .../storage/simple_kv/test/case-601.ini | 1 - .../storage/simple_kv/test/case-602.ini | 1 - .../storage/simple_kv/test/case-603.ini | 1 - src/replica/storage/simple_kv/test/config.ini | 2 - src/replica/test/config-test.ini | 1 - src/rpc/dns_resolver.cpp | 1 + src/rpc/rpc_host_port.cpp | 5 +- src/rpc/test/rpc_holder_test.cpp | 1 - src/runtime/global_config.h | 2 - src/runtime/nativerun.cpp | 26 +- src/runtime/scheduler.cpp | 1 - src/runtime/service_api_c.cpp | 42 +- src/runtime/simulator.cpp | 36 +- src/runtime/test/config-test-sim.ini | 1 - src/runtime/test/config-test.ini | 1 - src/runtime/tool_api.h | 1 - src/sample/config.ini | 2 - src/security/sasl_init.cpp | 18 +- src/server/available_detector.cpp | 1 - src/server/config.ini | 1 - src/server/pegasus_mutation_duplicator.cpp | 1 - src/server/pegasus_server_write.cpp | 1 - src/server/result_writer.cpp | 1 + .../test/capacity_unit_calculator_test.cpp | 3 +- src/server/test/config.ini | 2 - src/server/test/hashkey_transform_test.cpp | 1 - src/server/test/hotkey_collector_test.cpp | 1 - src/server/test/pegasus_server_write_test.cpp | 3 +- .../test/pegasus_write_service_impl_test.cpp | 11 +- .../test/pegasus_write_service_test.cpp | 3 +- src/server/test/rocksdb_wrapper_test.cpp | 11 +- src/shell/config.ini | 2 - src/task/tests/async_call_test.cpp | 1 - src/test/bench_test/config.ini | 2 - .../function_test/base_api/test_batch_get.cpp | 3 +- src/test/function_test/config.ini | 2 - src/test/kill_test/config.ini | 2 - src/test/pressure_test/config-pressure.ini | 3 - src/utils/CMakeLists.txt | 3 +- src/utils/api_utilities.h | 62 +-- src/utils/enum_helper.h | 3 +- src/utils/fmt_logging.h | 35 +- src/utils/logging.cpp | 245 +++++++--- src/utils/logging.h | 42 ++ src/utils/logging_provider.h | 92 ---- src/utils/simple_logger.cpp | 427 ------------------ src/utils/simple_logger.h | 124 ----- src/utils/test/CMakeLists.txt | 8 +- src/utils/test/config.ini | 27 ++ src/utils/test/endian_test.cpp | 4 +- src/utils/test/logger.cpp | 170 ------- src/utils/test/logging.cpp | 87 ++-- src/utils/test/main.cpp | 9 +- src/utils/timer.h | 35 +- src/zookeeper/test/config-test.ini | 1 - 135 files changed, 442 insertions(+), 1273 deletions(-) create mode 100644 src/utils/logging.h delete mode 100644 src/utils/logging_provider.h delete mode 100644 src/utils/simple_logger.cpp delete mode 100644 src/utils/simple_logger.h create mode 100644 src/utils/test/config.ini delete mode 100644 src/utils/test/logger.cpp diff --git a/.clang-tidy b/.clang-tidy index 888e91b95b..95e7592f88 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,7 +20,7 @@ CheckOptions: [] # Disable some checks that are not useful for us now. # They are sorted by names, and should be consistent to build_tools/clang_tidy.py. -Checks: 'abseil-*,boost-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,darwin-*,fuchsia-*,google-*,hicpp-*,linuxkernel-*,llvm-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-bugprone-easily-swappable-parameters,-bugprone-lambda-function-name,-bugprone-macro-parentheses,-cert-err58-cpp,-concurrency-mt-unsafe,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-union-access,-fuchsia-default-arguments-calls,-fuchsia-overloaded-operator,-fuchsia-statically-constructed-objects,-google-readability-avoid-underscore-in-googletest-name,-hicpp-avoid-c-arrays,-hicpp-named-parameter,-hicpp-no-array-decay,-llvm-include-order,-misc-definitions-in-headers,-misc-non-private-member-variables-in-classes,-modernize-avoid-c-arrays,-modernize-replace-disallow-copy-and-assign-macro,-modernize-use-trailing-return-type,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-magic-numbers,-readability-named-parameter' +Checks: 'abseil-*,boost-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,darwin-*,fuchsia-*,google-*,hicpp-*,linuxkernel-*,llvm-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-bugprone-easily-swappable-parameters,-bugprone-lambda-function-name,-bugprone-macro-parentheses,-cert-err58-cpp,-concurrency-mt-unsafe,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-union-access,-fuchsia-default-arguments-calls,-fuchsia-overloaded-operator,-fuchsia-statically-constructed-objects,-google-readability-avoid-underscore-in-googletest-name,-hicpp-avoid-c-arrays,-hicpp-named-parameter,-hicpp-no-array-decay,-llvm-header-guard,-llvm-include-order,-misc-definitions-in-headers,-misc-non-private-member-variables-in-classes,-modernize-avoid-c-arrays,-modernize-replace-disallow-copy-and-assign-macro,-modernize-use-trailing-return-type,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-magic-numbers,-readability-named-parameter' ExtraArgs: ExtraArgsBefore: [] FormatStyle: none diff --git a/.licenserc.yaml b/.licenserc.yaml index 49ab4b54a6..7c15f9cce9 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -609,8 +609,6 @@ header: - 'src/utils/ports.h' - 'src/utils/priority_queue.h' - 'src/utils/shared_io_service.h' - - 'src/utils/simple_logger.cpp' - - 'src/utils/simple_logger.h' - 'src/utils/singleton_store.h' - 'src/utils/strings.cpp' - 'src/utils/strings.h' @@ -632,7 +630,6 @@ header: - 'src/utils/test/join_point_test.cpp' - 'src/utils/test/json_helper_test.cpp' - 'src/utils/test/lock.std.cpp' - - 'src/utils/test/logger.cpp' - 'src/utils/test/logging.cpp' - 'src/utils/test/output_utils_test.cpp' - 'src/utils/test/priority_queue.cpp' diff --git a/build_tools/clang_tidy.py b/build_tools/clang_tidy.py index b2ef72d9bb..4a8d92164d 100755 --- a/build_tools/clang_tidy.py +++ b/build_tools/clang_tidy.py @@ -53,8 +53,6 @@ def tidy_on_path(path): "--", path] subprocess.check_call(cmd, stdout=patch_file, cwd=ROOT) - # TODO(yingchun): some checks could be disabled before we fix them. - # "-checks=-llvm-include-order,-modernize-concat-nested-namespaces,-cppcoreguidelines-macro-usage,-cppcoreguidelines-special-member-functions,-hicpp-special-member-functions,-bugprone-easily-swappable-parameters,-google-readability-avoid-underscore-in-googletest-name,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-llvm-header-guard,-cppcoreguidelines-pro-bounds-pointer-arithmetic", cmdline = ["clang-tidy-diff", "-clang-tidy-binary", "clang-tidy", @@ -84,6 +82,7 @@ def tidy_on_path(path): "-hicpp-avoid-c-arrays," "-hicpp-named-parameter," "-hicpp-no-array-decay," + "-llvm-header-guard," "-llvm-include-order," "-misc-definitions-in-headers," "-misc-non-private-member-variables-in-classes," diff --git a/cmake_modules/BaseFunctions.cmake b/cmake_modules/BaseFunctions.cmake index 9b784dc441..2933d0a04e 100644 --- a/cmake_modules/BaseFunctions.cmake +++ b/cmake_modules/BaseFunctions.cmake @@ -216,6 +216,12 @@ function(dsn_setup_compiler_flags) if(${BUILD_TEST}) add_definitions(-DMOCK_TEST) endif() + # Use external fmt library instead of spdlog bundled. + add_definitions(-DSPDLOG_FMT_EXTERNAL) + # Define the compile time lowest log level to be active. + add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG) + # Compile with -fno-exceptions. Call abort() on any spdlog exceptions. + add_definitions(-DSPDLOG_NO_EXCEPTIONS=ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -gdwarf-4" CACHE STRING "" FORCE) diff --git a/src/aio/test/config.ini b/src/aio/test/config.ini index fd46a38d75..4b20473cfc 100644 --- a/src/aio/test/config.ini +++ b/src/aio/test/config.ini @@ -42,7 +42,6 @@ enable_default_app_mimic = true tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [aio_test] op_buffer_size = 12 diff --git a/src/base/test/config.ini b/src/base/test/config.ini index d58db87e4b..510e17ae9d 100644 --- a/src/base/test/config.ini +++ b/src/base/test/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/block_service/test/config-test.ini b/src/block_service/test/config-test.ini index 19a33003c3..e82a09ae4c 100644 --- a/src/block_service/test/config-test.ini +++ b/src/block_service/test/config-test.ini @@ -37,7 +37,6 @@ pools = THREAD_POOL_DEFAULT,THREAD_POOL_BLOCK_SERVICE tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] fast_flush = true diff --git a/src/client/test/config.ini b/src/client/test/config.ini index 6c6ab5adcd..7b5fee9b32 100644 --- a/src/client/test/config.ini +++ b/src/client/test/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = false enable_default_app_mimic = true diff --git a/src/client_lib/pegasus_client_impl.cpp b/src/client_lib/pegasus_client_impl.cpp index 1dd402bd01..4baff6f619 100644 --- a/src/client_lib/pegasus_client_impl.cpp +++ b/src/client_lib/pegasus_client_impl.cpp @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/src/common/test/config-test.ini b/src/common/test/config-test.ini index 2775e06bd4..52402a9c6f 100644 --- a/src/common/test/config-test.ini +++ b/src/common/test/config-test.ini @@ -47,8 +47,6 @@ cli_local = false cli_remote = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - [tools.simple_logger] fast_flush = true diff --git a/src/failure_detector/test/config-test.ini b/src/failure_detector/test/config-test.ini index ef927dcc24..3c637f1d3f 100644 --- a/src/failure_detector/test/config-test.ini +++ b/src/failure_detector/test/config-test.ini @@ -71,7 +71,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] diff --git a/src/failure_detector/test/config-whitelist-test-failed.ini b/src/failure_detector/test/config-whitelist-test-failed.ini index 8f91ccdf98..7fe3a0e2ac 100644 --- a/src/failure_detector/test/config-whitelist-test-failed.ini +++ b/src/failure_detector/test/config-whitelist-test-failed.ini @@ -72,7 +72,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] diff --git a/src/failure_detector/test/config-whitelist-test.ini b/src/failure_detector/test/config-whitelist-test.ini index 0ce1373c99..21346d4076 100644 --- a/src/failure_detector/test/config-whitelist-test.ini +++ b/src/failure_detector/test/config-whitelist-test.ini @@ -72,7 +72,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] diff --git a/src/geo/bench/config.ini b/src/geo/bench/config.ini index ca4d84f1f1..60d715f88d 100644 --- a/src/geo/bench/config.ini +++ b/src/geo/bench/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/geo/test/config.ini b/src/geo/test/config.ini index acc3fbc2a6..40efc8ac7f 100644 --- a/src/geo/test/config.ini +++ b/src/geo/test/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/gutil/test/map_util_unittest.cpp b/src/gutil/test/map_util_unittest.cpp index 8f68bf50a2..74572acac6 100644 --- a/src/gutil/test/map_util_unittest.cpp +++ b/src/gutil/test/map_util_unittest.cpp @@ -17,9 +17,7 @@ #include "gutil/map_util.h" #include -#include -#include -#include +#include #include #include #include @@ -27,6 +25,7 @@ #include #include #include +#include #include #include diff --git a/src/http/pprof_http_service.cpp b/src/http/pprof_http_service.cpp index d7246ae69d..436f8a9c84 100644 --- a/src/http/pprof_http_service.cpp +++ b/src/http/pprof_http_service.cpp @@ -19,8 +19,9 @@ #include "pprof_http_service.h" -#include -#include +// IWYU pragma: no_include +#include +#include #include #include #include @@ -41,7 +42,6 @@ #include "http/http_server.h" #include "http/http_status_code.h" #include "runtime/api_layer1.h" -#include "utils/api_utilities.h" #include "utils/blob.h" #include "utils/defer.h" #include "utils/fmt_logging.h" @@ -98,7 +98,7 @@ static bool has_ext(const std::string &name, const std::string &ext) static int extract_symbols_from_binary(std::map &addr_map, const lib_info &lib_info) { - SCOPED_LOG_TIMING(INFO, "load {}", lib_info.path); + SCOPED_LOG_TIMING(info, "load {}", lib_info.path); std::string cmd = "nm -C -p "; cmd.append(lib_info.path); std::stringstream ss; @@ -195,8 +195,8 @@ static int extract_symbols_from_binary(std::map &addr_ma static void load_symbols() { - SCOPED_LOG_TIMING(INFO, "load all symbols"); - auto fp = fopen("/proc/self/maps", "r"); + SCOPED_LOG_TIMING(info, "load all symbols"); + auto *fp = fopen("/proc/self/maps", "r"); if (fp == nullptr) { return; } @@ -267,7 +267,7 @@ static void load_symbols() extract_symbols_from_binary(symbol_map, info); size_t num_removed = 0; - LOG_TIMING_IF(INFO, num_removed > 0, "removed {} entries", num_removed); + LOG_TIMING_IF(info, num_removed > 0, "removed {} entries", num_removed); bool last_is_empty = false; for (auto it = symbol_map.begin(); it != symbol_map.end();) { if (it->second.empty()) { diff --git a/src/http/test/config-test.ini b/src/http/test/config-test.ini index 744d8d412a..bb52addbf2 100644 --- a/src/http/test/config-test.ini +++ b/src/http/test/config-test.ini @@ -38,7 +38,6 @@ toollets = tracer, profiler pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] fast_flush = true diff --git a/src/meta/duplication/meta_duplication_service.cpp b/src/meta/duplication/meta_duplication_service.cpp index 66cd2ed125..cf275c3f24 100644 --- a/src/meta/duplication/meta_duplication_service.cpp +++ b/src/meta/duplication/meta_duplication_service.cpp @@ -46,8 +46,8 @@ #include "rpc/rpc_message.h" #include "rpc/serialization.h" #include "runtime/api_layer1.h" +#include "spdlog/common.h" #include "task/async_calls.h" -#include "utils/api_utilities.h" #include "utils/blob.h" #include "utils/chrono_literals.h" #include "utils/error_code.h" @@ -178,10 +178,10 @@ void meta_duplication_service::do_modify_duplication(std::shared_ptr } while (0) #define LOG_WARNING_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, ...) \ - LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, LOG_LEVEL_WARNING, __VA_ARGS__) + LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, spdlog::level::warn, __VA_ARGS__) #define LOG_ERROR_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, ...) \ - LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, LOG_LEVEL_ERROR, __VA_ARGS__) + LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, spdlog::level::err, __VA_ARGS__) // This call will not recreate if the duplication // with the same app name and remote end point already exists. diff --git a/src/meta/test/config-test.ini b/src/meta/test/config-test.ini index ca5fdf2c75..0d92b8ff86 100644 --- a/src/meta/test/config-test.ini +++ b/src/meta/test/config-test.ini @@ -45,8 +45,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - [tools.simple_logger] fast_flush = true diff --git a/src/meta/test/dump_file.cpp b/src/meta/test/dump_file.cpp index b1528c8816..5d273d2b45 100644 --- a/src/meta/test/dump_file.cpp +++ b/src/meta/test/dump_file.cpp @@ -24,9 +24,10 @@ * THE SOFTWARE. */ -#include -#include -#include +#include // IWYU pragma: keep +#include +#include +#include #include #include #include diff --git a/src/meta/test/meta_state/config-test.ini b/src/meta/test/meta_state/config-test.ini index f65c817fbe..4a07e5f6d6 100644 --- a/src/meta/test/meta_state/config-test.ini +++ b/src/meta/test/meta_state/config-test.ini @@ -55,8 +55,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - [tools.simple_logger] fast_flush = true diff --git a/src/nfs/test/config.ini b/src/nfs/test/config.ini index 214ae2f431..94ce7b3369 100644 --- a/src/nfs/test/config.ini +++ b/src/nfs/test/config.ini @@ -39,4 +39,3 @@ enable_default_app_mimic = true tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger diff --git a/src/nfs/test/nfs_test_file1 b/src/nfs/test/nfs_test_file1 index 920a9290f2..e8b4bb3a03 100644 --- a/src/nfs/test/nfs_test_file1 +++ b/src/nfs/test/nfs_test_file1 @@ -56,8 +56,6 @@ cli_local = true cli_remote = true logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - [tools.simulator] random_seed = 0 diff --git a/src/nfs/test/nfs_test_file2 b/src/nfs/test/nfs_test_file2 index d37a578dd1..65e7e365c8 100644 --- a/src/nfs/test/nfs_test_file2 +++ b/src/nfs/test/nfs_test_file2 @@ -43,9 +43,6 @@ cli_local = true cli_remote = true logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - - [tools.simulator] random_seed = 0 diff --git a/src/redis_protocol/proxy/config.ini b/src/redis_protocol/proxy/config.ini index 89c142010f..5968f35a73 100644 --- a/src/redis_protocol/proxy/config.ini +++ b/src/redis_protocol/proxy/config.ini @@ -44,8 +44,6 @@ toollets = profiler pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger enable_default_app_mimic = true [tools.simple_logger] diff --git a/src/redis_protocol/proxy_ut/config.ini b/src/redis_protocol/proxy_ut/config.ini index bf525ea950..e03da86130 100644 --- a/src/redis_protocol/proxy_ut/config.ini +++ b/src/redis_protocol/proxy_ut/config.ini @@ -44,8 +44,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger enable_default_app_mimic = true [tools.simple_logger] diff --git a/src/replica/bulk_load/test/config-test.ini b/src/replica/bulk_load/test/config-test.ini index 2ac30a6c68..0b5e510220 100644 --- a/src/replica/bulk_load/test/config-test.ini +++ b/src/replica/bulk_load/test/config-test.ini @@ -45,8 +45,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - [tools.simple_logger] fast_flush = true diff --git a/src/replica/replica_2pc.cpp b/src/replica/replica_2pc.cpp index 884c5c4dc3..70a87bfd28 100644 --- a/src/replica/replica_2pc.cpp +++ b/src/replica/replica_2pc.cpp @@ -62,12 +62,12 @@ #include "rpc/serialization.h" #include "runtime/api_layer1.h" #include "security/access_controller.h" +#include "spdlog/common.h" #include "split/replica_split_manager.h" #include "task/async_calls.h" #include "task/task.h" #include "task/task_code.h" #include "task/task_spec.h" -#include "utils/api_utilities.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" #include "utils/flags.h" @@ -238,14 +238,15 @@ void replica::init_prepare(mutation_ptr &mu, bool reconciliation, bool pop_all_c const auto request_count = mu->client_requests.size(); mu->data.header.last_committed_decree = last_committed_decree(); - log_level_t level = LOG_LEVEL_DEBUG; + spdlog::level::level_enum level = spdlog::level::debug; if (mu->data.header.decree == invalid_decree) { mu->set_id(get_ballot(), _prepare_list->max_decree() + 1); // print a debug log if necessary if (FLAGS_prepare_decree_gap_for_debug_logging > 0 && - mu->get_decree() % FLAGS_prepare_decree_gap_for_debug_logging == 0) - level = LOG_LEVEL_INFO; - mu->set_timestamp(_uniq_timestamp_us.next()); + mu->get_decree() % FLAGS_prepare_decree_gap_for_debug_logging == 0) { + level = spdlog::level::info; + } + mu->set_timestamp(static_cast(_uniq_timestamp_us.next())); } else { mu->set_id(get_ballot(), mu->data.header.decree); } diff --git a/src/replica/split/test/config-test.ini b/src/replica/split/test/config-test.ini index 906f6ce3c6..86160581af 100644 --- a/src/replica/split/test/config-test.ini +++ b/src/replica/split/test/config-test.ini @@ -45,8 +45,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger - [tools.simple_logger] fast_flush = true diff --git a/src/replica/storage/simple_kv/config.ini b/src/replica/storage/simple_kv/config.ini index d4b7ae8f05..0f8712e368 100644 --- a/src/replica/storage/simple_kv/config.ini +++ b/src/replica/storage/simple_kv/config.ini @@ -64,8 +64,6 @@ toollets = tracer, profiler, fault_injector pause_on_start = false ;logging_start_level = LOG_LEVEL_WARNING -;logging_factory_name = dsn::tools::screen_logger -;logging_factory_name = dsn::tools::hpc_logger [tools.simulator] random_seed = 0 diff --git a/src/replica/storage/simple_kv/test/case-000.ini b/src/replica/storage/simple_kv/test/case-000.ini index 34d18892fc..0060218f83 100644 --- a/src/replica/storage/simple_kv/test/case-000.ini +++ b/src/replica/storage/simple_kv/test/case-000.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-001.ini b/src/replica/storage/simple_kv/test/case-001.ini index edf1d69f46..254e0fbc40 100644 --- a/src/replica/storage/simple_kv/test/case-001.ini +++ b/src/replica/storage/simple_kv/test/case-001.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-002.ini b/src/replica/storage/simple_kv/test/case-002.ini index d3012ab436..63fac07ed7 100644 --- a/src/replica/storage/simple_kv/test/case-002.ini +++ b/src/replica/storage/simple_kv/test/case-002.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-003.ini b/src/replica/storage/simple_kv/test/case-003.ini index 86e91c5345..f1038f1d6a 100644 --- a/src/replica/storage/simple_kv/test/case-003.ini +++ b/src/replica/storage/simple_kv/test/case-003.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-004.ini b/src/replica/storage/simple_kv/test/case-004.ini index e523a8d643..31a0cde89f 100644 --- a/src/replica/storage/simple_kv/test/case-004.ini +++ b/src/replica/storage/simple_kv/test/case-004.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-005.ini b/src/replica/storage/simple_kv/test/case-005.ini index 8e28e7b894..dd441531e1 100644 --- a/src/replica/storage/simple_kv/test/case-005.ini +++ b/src/replica/storage/simple_kv/test/case-005.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-006.ini b/src/replica/storage/simple_kv/test/case-006.ini index 386433359b..9d09a58a06 100644 --- a/src/replica/storage/simple_kv/test/case-006.ini +++ b/src/replica/storage/simple_kv/test/case-006.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-100.ini b/src/replica/storage/simple_kv/test/case-100.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-100.ini +++ b/src/replica/storage/simple_kv/test/case-100.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-101.ini b/src/replica/storage/simple_kv/test/case-101.ini index 2c840a8925..706eef863c 100644 --- a/src/replica/storage/simple_kv/test/case-101.ini +++ b/src/replica/storage/simple_kv/test/case-101.ini @@ -65,7 +65,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-102.ini b/src/replica/storage/simple_kv/test/case-102.ini index 99392e8056..138060c308 100644 --- a/src/replica/storage/simple_kv/test/case-102.ini +++ b/src/replica/storage/simple_kv/test/case-102.ini @@ -65,7 +65,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-103.ini b/src/replica/storage/simple_kv/test/case-103.ini index 10b312756d..0456b25712 100644 --- a/src/replica/storage/simple_kv/test/case-103.ini +++ b/src/replica/storage/simple_kv/test/case-103.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-104.ini b/src/replica/storage/simple_kv/test/case-104.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-104.ini +++ b/src/replica/storage/simple_kv/test/case-104.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-105.ini b/src/replica/storage/simple_kv/test/case-105.ini index 3019495bc4..031ad80412 100644 --- a/src/replica/storage/simple_kv/test/case-105.ini +++ b/src/replica/storage/simple_kv/test/case-105.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-106.ini b/src/replica/storage/simple_kv/test/case-106.ini index 2c840a8925..706eef863c 100644 --- a/src/replica/storage/simple_kv/test/case-106.ini +++ b/src/replica/storage/simple_kv/test/case-106.ini @@ -65,7 +65,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-107.ini b/src/replica/storage/simple_kv/test/case-107.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-107.ini +++ b/src/replica/storage/simple_kv/test/case-107.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-108.ini b/src/replica/storage/simple_kv/test/case-108.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-108.ini +++ b/src/replica/storage/simple_kv/test/case-108.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-109.ini b/src/replica/storage/simple_kv/test/case-109.ini index d489c02923..fff0f9824a 100644 --- a/src/replica/storage/simple_kv/test/case-109.ini +++ b/src/replica/storage/simple_kv/test/case-109.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-200.ini b/src/replica/storage/simple_kv/test/case-200.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-200.ini +++ b/src/replica/storage/simple_kv/test/case-200.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-201.ini b/src/replica/storage/simple_kv/test/case-201.ini index b6801a0640..843d40d240 100644 --- a/src/replica/storage/simple_kv/test/case-201.ini +++ b/src/replica/storage/simple_kv/test/case-201.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-202-0.ini b/src/replica/storage/simple_kv/test/case-202-0.ini index a0fa07b3f5..f4b20428fd 100644 --- a/src/replica/storage/simple_kv/test/case-202-0.ini +++ b/src/replica/storage/simple_kv/test/case-202-0.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-202-1.ini b/src/replica/storage/simple_kv/test/case-202-1.ini index e523a8d643..31a0cde89f 100644 --- a/src/replica/storage/simple_kv/test/case-202-1.ini +++ b/src/replica/storage/simple_kv/test/case-202-1.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-203-0.ini b/src/replica/storage/simple_kv/test/case-203-0.ini index a0fa07b3f5..f4b20428fd 100644 --- a/src/replica/storage/simple_kv/test/case-203-0.ini +++ b/src/replica/storage/simple_kv/test/case-203-0.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-204.ini b/src/replica/storage/simple_kv/test/case-204.ini index 7ddbb8db2d..f840f32e8a 100644 --- a/src/replica/storage/simple_kv/test/case-204.ini +++ b/src/replica/storage/simple_kv/test/case-204.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-205.ini b/src/replica/storage/simple_kv/test/case-205.ini index 602794b67f..045e7fe59e 100644 --- a/src/replica/storage/simple_kv/test/case-205.ini +++ b/src/replica/storage/simple_kv/test/case-205.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-206.ini b/src/replica/storage/simple_kv/test/case-206.ini index 28d2c4aaf0..91a692a223 100644 --- a/src/replica/storage/simple_kv/test/case-206.ini +++ b/src/replica/storage/simple_kv/test/case-206.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-207.ini b/src/replica/storage/simple_kv/test/case-207.ini index 7ddbb8db2d..f840f32e8a 100644 --- a/src/replica/storage/simple_kv/test/case-207.ini +++ b/src/replica/storage/simple_kv/test/case-207.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-208.ini b/src/replica/storage/simple_kv/test/case-208.ini index 7ddbb8db2d..f840f32e8a 100644 --- a/src/replica/storage/simple_kv/test/case-208.ini +++ b/src/replica/storage/simple_kv/test/case-208.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-209.ini b/src/replica/storage/simple_kv/test/case-209.ini index 7ddbb8db2d..f840f32e8a 100644 --- a/src/replica/storage/simple_kv/test/case-209.ini +++ b/src/replica/storage/simple_kv/test/case-209.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-210.ini b/src/replica/storage/simple_kv/test/case-210.ini index 2652fed838..74a46f3a01 100644 --- a/src/replica/storage/simple_kv/test/case-210.ini +++ b/src/replica/storage/simple_kv/test/case-210.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-211.ini b/src/replica/storage/simple_kv/test/case-211.ini index d07b7fcb86..6239105f94 100644 --- a/src/replica/storage/simple_kv/test/case-211.ini +++ b/src/replica/storage/simple_kv/test/case-211.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-212.ini b/src/replica/storage/simple_kv/test/case-212.ini index 1b3c09bd1c..de8d544059 100644 --- a/src/replica/storage/simple_kv/test/case-212.ini +++ b/src/replica/storage/simple_kv/test/case-212.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-213.ini b/src/replica/storage/simple_kv/test/case-213.ini index 3098910b7e..9ae63a32cf 100644 --- a/src/replica/storage/simple_kv/test/case-213.ini +++ b/src/replica/storage/simple_kv/test/case-213.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-214.ini b/src/replica/storage/simple_kv/test/case-214.ini index 602794b67f..045e7fe59e 100644 --- a/src/replica/storage/simple_kv/test/case-214.ini +++ b/src/replica/storage/simple_kv/test/case-214.ini @@ -67,7 +67,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-215.ini b/src/replica/storage/simple_kv/test/case-215.ini index 28d2c4aaf0..91a692a223 100644 --- a/src/replica/storage/simple_kv/test/case-215.ini +++ b/src/replica/storage/simple_kv/test/case-215.ini @@ -68,7 +68,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-216.ini b/src/replica/storage/simple_kv/test/case-216.ini index 7ddbb8db2d..f840f32e8a 100644 --- a/src/replica/storage/simple_kv/test/case-216.ini +++ b/src/replica/storage/simple_kv/test/case-216.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-300-0.ini b/src/replica/storage/simple_kv/test/case-300-0.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-300-0.ini +++ b/src/replica/storage/simple_kv/test/case-300-0.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-300-1.ini b/src/replica/storage/simple_kv/test/case-300-1.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-300-1.ini +++ b/src/replica/storage/simple_kv/test/case-300-1.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-300-2.ini b/src/replica/storage/simple_kv/test/case-300-2.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-300-2.ini +++ b/src/replica/storage/simple_kv/test/case-300-2.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-301.ini b/src/replica/storage/simple_kv/test/case-301.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-301.ini +++ b/src/replica/storage/simple_kv/test/case-301.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-302.ini b/src/replica/storage/simple_kv/test/case-302.ini index fcab05e782..5c4c60e52b 100644 --- a/src/replica/storage/simple_kv/test/case-302.ini +++ b/src/replica/storage/simple_kv/test/case-302.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-303.ini b/src/replica/storage/simple_kv/test/case-303.ini index e3fefc0fb3..e53fa4928a 100644 --- a/src/replica/storage/simple_kv/test/case-303.ini +++ b/src/replica/storage/simple_kv/test/case-303.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-304.ini b/src/replica/storage/simple_kv/test/case-304.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-304.ini +++ b/src/replica/storage/simple_kv/test/case-304.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-305.ini b/src/replica/storage/simple_kv/test/case-305.ini index e3fefc0fb3..e53fa4928a 100644 --- a/src/replica/storage/simple_kv/test/case-305.ini +++ b/src/replica/storage/simple_kv/test/case-305.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-306.ini b/src/replica/storage/simple_kv/test/case-306.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-306.ini +++ b/src/replica/storage/simple_kv/test/case-306.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-307.ini b/src/replica/storage/simple_kv/test/case-307.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-307.ini +++ b/src/replica/storage/simple_kv/test/case-307.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-400.ini b/src/replica/storage/simple_kv/test/case-400.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-400.ini +++ b/src/replica/storage/simple_kv/test/case-400.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-401.ini b/src/replica/storage/simple_kv/test/case-401.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-401.ini +++ b/src/replica/storage/simple_kv/test/case-401.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-402.ini b/src/replica/storage/simple_kv/test/case-402.ini index fb366b244e..48168faa8c 100644 --- a/src/replica/storage/simple_kv/test/case-402.ini +++ b/src/replica/storage/simple_kv/test/case-402.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-600.ini b/src/replica/storage/simple_kv/test/case-600.ini index 386433359b..9d09a58a06 100644 --- a/src/replica/storage/simple_kv/test/case-600.ini +++ b/src/replica/storage/simple_kv/test/case-600.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-601.ini b/src/replica/storage/simple_kv/test/case-601.ini index f9e2f3b969..6a79f439fc 100644 --- a/src/replica/storage/simple_kv/test/case-601.ini +++ b/src/replica/storage/simple_kv/test/case-601.ini @@ -69,7 +69,6 @@ toollets = tracer,test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-602.ini b/src/replica/storage/simple_kv/test/case-602.ini index 386433359b..9d09a58a06 100644 --- a/src/replica/storage/simple_kv/test/case-602.ini +++ b/src/replica/storage/simple_kv/test/case-602.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/case-603.ini b/src/replica/storage/simple_kv/test/case-603.ini index dd29d532db..2fb5063193 100644 --- a/src/replica/storage/simple_kv/test/case-603.ini +++ b/src/replica/storage/simple_kv/test/case-603.ini @@ -69,7 +69,6 @@ toollets = test_injector pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] short_header = false diff --git a/src/replica/storage/simple_kv/test/config.ini b/src/replica/storage/simple_kv/test/config.ini index 5622b9ff0f..bec7c05e66 100644 --- a/src/replica/storage/simple_kv/test/config.ini +++ b/src/replica/storage/simple_kv/test/config.ini @@ -86,8 +86,6 @@ toollets = tracer, profiler, fault_injector pause_on_start = false ;logging_start_level = LOG_LEVEL_WARNING -;logging_factory_name = dsn::tools::screen_logger -;logging_factory_name = dsn::tools::hpc_logger [tools.simulator] random_seed = 0 diff --git a/src/replica/test/config-test.ini b/src/replica/test/config-test.ini index 2d2c6f3974..1572e489a5 100644 --- a/src/replica/test/config-test.ini +++ b/src/replica/test/config-test.ini @@ -45,7 +45,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger] diff --git a/src/rpc/dns_resolver.cpp b/src/rpc/dns_resolver.cpp index 9ddc10a7fe..4e96052a97 100644 --- a/src/rpc/dns_resolver.cpp +++ b/src/rpc/dns_resolver.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "fmt/core.h" diff --git a/src/rpc/rpc_host_port.cpp b/src/rpc/rpc_host_port.cpp index d7e4bd2b60..b6057caa5f 100644 --- a/src/rpc/rpc_host_port.cpp +++ b/src/rpc/rpc_host_port.cpp @@ -30,7 +30,6 @@ #include "fmt/core.h" #include "rpc/group_host_port.h" #include "rpc/rpc_host_port.h" -#include "utils/api_utilities.h" #include "utils/error_code.h" #include "utils/ports.h" #include "utils/safe_strerror_posix.h" @@ -55,7 +54,7 @@ host_port host_port::from_address(rpc_address addr) { host_port hp; SCOPED_LOG_SLOW_EXECUTION( - WARNING, 100, "construct host_port '{}' from rpc_address '{}'", hp, addr); + warn, 100, "construct host_port '{}' from rpc_address '{}'", hp, addr); switch (addr.type()) { case HOST_TYPE_IPV4: { const auto s = lookup_hostname(htonl(addr.ip()), &hp._host); @@ -81,7 +80,7 @@ host_port host_port::from_string(const std::string &host_port_str) { host_port hp; SCOPED_LOG_SLOW_EXECUTION( - WARNING, 100, "construct host_port '{}' from string '{}'", hp, host_port_str); + warn, 100, "construct host_port '{}' from string '{}'", hp, host_port_str); const auto pos = host_port_str.find_last_of(':'); if (dsn_unlikely(pos == std::string::npos)) { return hp; diff --git a/src/rpc/test/rpc_holder_test.cpp b/src/rpc/test/rpc_holder_test.cpp index 37a7bea11a..8656faa6b0 100644 --- a/src/rpc/test/rpc_holder_test.cpp +++ b/src/rpc/test/rpc_holder_test.cpp @@ -26,7 +26,6 @@ #include "rpc/rpc_holder.h" -#include #include #include "common/gpid.h" diff --git a/src/runtime/global_config.h b/src/runtime/global_config.h index 87c36cb975..cfd5d46250 100644 --- a/src/runtime/global_config.h +++ b/src/runtime/global_config.h @@ -162,7 +162,6 @@ struct service_spec std::string lock_nr_factory_name; std::string rwlock_nr_factory_name; std::string semaphore_factory_name; - std::string logging_factory_name; network_client_configs network_default_client_cfs; // default network configed by tools network_server_configs network_default_server_cfs; // default network configed by tools @@ -205,6 +204,5 @@ CONFIG_FLD_STRING(lock_factory_name, "", "recursive exclusive lock provider") CONFIG_FLD_STRING(lock_nr_factory_name, "", "non-recurisve exclusive lock provider") CONFIG_FLD_STRING(rwlock_nr_factory_name, "", "non-recurisve rwlock provider") CONFIG_FLD_STRING(semaphore_factory_name, "", "semaphore provider") -CONFIG_FLD_STRING(logging_factory_name, "", "The implementation class of logging service") CONFIG_END } // namespace dsn diff --git a/src/runtime/nativerun.cpp b/src/runtime/nativerun.cpp index dbaa880732..4f3dcf64ad 100644 --- a/src/runtime/nativerun.cpp +++ b/src/runtime/nativerun.cpp @@ -78,29 +78,29 @@ void nativerun::install(service_spec &spec) } } - if (spec.logging_factory_name == "") - spec.logging_factory_name = "dsn::tools::simple_logger"; - - if (spec.lock_factory_name == "") + if (spec.lock_factory_name.empty()) { spec.lock_factory_name = ("dsn::tools::std_lock_provider"); - - if (spec.lock_nr_factory_name == "") + } + if (spec.lock_nr_factory_name.empty()) { spec.lock_nr_factory_name = ("dsn::tools::std_lock_nr_provider"); + } - if (spec.rwlock_nr_factory_name == "") + if (spec.rwlock_nr_factory_name.empty()) { spec.rwlock_nr_factory_name = ("dsn::tools::std_rwlock_nr_provider"); + } - if (spec.semaphore_factory_name == "") + if (spec.semaphore_factory_name.empty()) { spec.semaphore_factory_name = ("dsn::tools::std_semaphore_provider"); + } - for (auto it = spec.threadpool_specs.begin(); it != spec.threadpool_specs.end(); ++it) { - threadpool_spec &tspec = *it; - - if (tspec.worker_factory_name == "") + for (auto &tspec : spec.threadpool_specs) { + if (tspec.worker_factory_name.empty()) { tspec.worker_factory_name = ("dsn::task_worker"); + } - if (tspec.queue_factory_name == "") + if (tspec.queue_factory_name.empty()) { tspec.queue_factory_name = ("dsn::tools::simple_task_queue"); + } } } diff --git a/src/runtime/scheduler.cpp b/src/runtime/scheduler.cpp index db9c79b2e7..a49d0908f8 100644 --- a/src/runtime/scheduler.cpp +++ b/src/runtime/scheduler.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "runtime/node_scoper.h" diff --git a/src/runtime/service_api_c.cpp b/src/runtime/service_api_c.cpp index ecf2aa564c..b32fdd5e61 100644 --- a/src/runtime/service_api_c.cpp +++ b/src/runtime/service_api_c.cpp @@ -57,14 +57,13 @@ #include "runtime/global_config.h" #include "runtime/service_app.h" #include "runtime/service_engine.h" +#include "runtime/tool_api.h" +#include "security/init.h" +#include "security/negotiation_manager.h" #include "task/task.h" #include "task/task_code.h" #include "task/task_engine.h" #include "task/task_spec.h" -#include "task/task_worker.h" -#include "runtime/tool_api.h" -#include "security/init.h" -#include "security/negotiation_manager.h" #include "utils/api_utilities.h" #include "utils/command_manager.h" #include "utils/config_api.h" @@ -75,12 +74,11 @@ #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/join_point.h" -#include "utils/logging_provider.h" +#include "utils/logging.h" #include "utils/process_utils.h" #include "utils/string_conv.h" #include "utils/strings.h" #include "utils/sys_exit_hook.h" -#include "utils/threadpool_spec.h" DSN_DEFINE_bool( core, @@ -343,33 +341,6 @@ inline void dsn_global_init() dsn::service_engine::instance(); } -static std::string dsn_log_prefixed_message_func() -{ - const int tid = dsn::utils::get_current_tid(); - const auto t = dsn::task::get_current_task_id(); - if (t) { - if (nullptr != dsn::task::get_current_worker2()) { - return fmt::format("{}.{}{}.{:016}: ", - dsn::task::get_current_node_name(), - dsn::task::get_current_worker2()->pool_spec().name, - dsn::task::get_current_worker2()->index(), - t); - } else { - return fmt::format( - "{}.io-thrd.{}.{:016}: ", dsn::task::get_current_node_name(), tid, t); - } - } else { - if (nullptr != dsn::task::get_current_worker2()) { - return fmt::format("{}.{}{}: ", - dsn::task::get_current_node_name(), - dsn::task::get_current_worker2()->pool_spec().name, - dsn::task::get_current_worker2()->index()); - } else { - return fmt::format("{}.io-thrd.{}: ", dsn::task::get_current_node_name(), tid); - } - } -} - bool run(const char *config_file, const char *config_arguments, bool is_server, @@ -473,10 +444,7 @@ bool run(const char *config_file, } // Initialize logging. - dsn_log_init(spec.logging_factory_name, - spec.log_dir, - fmt::format("{}", fmt::join(app_names, ".")), - dsn_log_prefixed_message_func); + dsn_log_init(spec.log_dir, fmt::format("{}", fmt::join(app_names, "."))); // Prepare the minimum necessary. ::dsn::service_engine::instance().init_before_toollets(spec); diff --git a/src/runtime/simulator.cpp b/src/runtime/simulator.cpp index 51aad7dcaf..a82ca95b39 100644 --- a/src/runtime/simulator.cpp +++ b/src/runtime/simulator.cpp @@ -68,11 +68,13 @@ void simulator::install(service_spec &spec) scheduler::instance(); - if (spec.env_factory_name == "") + if (spec.env_factory_name.empty()) { spec.env_factory_name = ("dsn::tools::sim_env_provider"); + } - if (spec.timer_factory_name == "") + if (spec.timer_factory_name.empty()) { spec.timer_factory_name = ("dsn::tools::sim_timer_service"); + } network_client_config cs; cs.factory_name = "dsn::tools::sim_network_provider"; @@ -89,29 +91,25 @@ void simulator::install(service_spec &spec) cs2.channel = RPC_CHANNEL_UDP; spec.network_default_server_cfs[cs2] = cs2; - if (spec.logging_factory_name == "") - spec.logging_factory_name = "dsn::tools::simple_logger"; - - if (spec.lock_factory_name == "") + if (spec.lock_factory_name.empty()) { spec.lock_factory_name = ("dsn::tools::sim_lock_provider"); - - if (spec.lock_nr_factory_name == "") + } + if (spec.lock_nr_factory_name.empty()) { spec.lock_nr_factory_name = ("dsn::tools::sim_lock_nr_provider"); - - if (spec.rwlock_nr_factory_name == "") + } + if (spec.rwlock_nr_factory_name.empty()) { spec.rwlock_nr_factory_name = ("dsn::tools::sim_rwlock_nr_provider"); - - if (spec.semaphore_factory_name == "") + } + if (spec.semaphore_factory_name.empty()) { spec.semaphore_factory_name = ("dsn::tools::sim_semaphore_provider"); - - for (auto it = spec.threadpool_specs.begin(); it != spec.threadpool_specs.end(); ++it) { - threadpool_spec &tspec = *it; - - if (tspec.worker_factory_name == "") + } + for (auto &tspec : spec.threadpool_specs) { + if (tspec.worker_factory_name.empty()) { tspec.worker_factory_name = ("dsn::task_worker"); - - if (tspec.queue_factory_name == "") + } + if (tspec.queue_factory_name.empty()) { tspec.queue_factory_name = ("dsn::tools::sim_task_queue"); + } } sys_exit.put_front(simulator::on_system_exit, "simulator"); diff --git a/src/runtime/test/config-test-sim.ini b/src/runtime/test/config-test-sim.ini index 6c54eba106..dc3aca3cbe 100644 --- a/src/runtime/test/config-test-sim.ini +++ b/src/runtime/test/config-test-sim.ini @@ -62,7 +62,6 @@ toollets = tracer, profiler pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger diff --git a/src/runtime/test/config-test.ini b/src/runtime/test/config-test.ini index 46681e369a..f8a2062cfb 100644 --- a/src/runtime/test/config-test.ini +++ b/src/runtime/test/config-test.ini @@ -75,7 +75,6 @@ toollets = tracer, profiler pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger diff --git a/src/runtime/tool_api.h b/src/runtime/tool_api.h index 20c87e2cdd..6d2f84ac70 100644 --- a/src/runtime/tool_api.h +++ b/src/runtime/tool_api.h @@ -51,7 +51,6 @@ Component providers define the interface for the local components (e.g., network #include "task/timer_service.h" #include "utils/factory_store.h" #include "utils/join_point.h" -#include "utils/logging_provider.h" // IWYU pragma: keep namespace dsn { class service_node; diff --git a/src/sample/config.ini b/src/sample/config.ini index 7c03372970..7b0af558f4 100644 --- a/src/sample/config.ini +++ b/src/sample/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/security/sasl_init.cpp b/src/security/sasl_init.cpp index 1f9712c34c..5c926044e3 100644 --- a/src/security/sasl_init.cpp +++ b/src/security/sasl_init.cpp @@ -22,7 +22,7 @@ #include #include "kinit_context.h" -#include "utils/api_utilities.h" +#include "spdlog/common.h" #include "utils/error_code.h" #include "utils/flags.h" #include "utils/fmt_logging.h" @@ -30,21 +30,20 @@ DSN_DEFINE_string(security, sasl_plugin_path, "/usr/lib/sasl2", "path to search sasl plugins"); -namespace dsn { -namespace security { +namespace dsn::security { -log_level_t get_log_level(int level) +spdlog::level::level_enum get_log_level(int level) { switch (level) { case SASL_LOG_ERR: - return LOG_LEVEL_ERROR; + return spdlog::level::err; case SASL_LOG_FAIL: case SASL_LOG_WARN: - return LOG_LEVEL_WARNING; + return spdlog::level::warn; case SASL_LOG_NOTE: - return LOG_LEVEL_INFO; + return spdlog::level::info; default: - return LOG_LEVEL_DEBUG; + return spdlog::level::debug; } } @@ -148,5 +147,4 @@ error_s init_sasl(bool is_server) } return ret; } -} // namespace security -} // namespace dsn +} // namespace dsn::security diff --git a/src/server/available_detector.cpp b/src/server/available_detector.cpp index 8b130e8b23..194a716c26 100644 --- a/src/server/available_detector.cpp +++ b/src/server/available_detector.cpp @@ -19,7 +19,6 @@ #include "available_detector.h" -#include #include // IWYU pragma: keep // IWYU pragma: no_include #include diff --git a/src/server/config.ini b/src/server/config.ini index 90caaa5f8a..9c91840c3a 100644 --- a/src/server/config.ini +++ b/src/server/config.ini @@ -64,7 +64,6 @@ tcmalloc_release_rate = 1.0 logging_start_level = LOG_LEVEL_INFO - logging_factory_name = dsn::tools::simple_logger logging_flush_on_exit = true [tools.simple_logger] diff --git a/src/server/pegasus_mutation_duplicator.cpp b/src/server/pegasus_mutation_duplicator.cpp index 091d1247a8..fabcfbf117 100644 --- a/src/server/pegasus_mutation_duplicator.cpp +++ b/src/server/pegasus_mutation_duplicator.cpp @@ -19,7 +19,6 @@ #include "pegasus_mutation_duplicator.h" -#include #include #include #include diff --git a/src/server/pegasus_server_write.cpp b/src/server/pegasus_server_write.cpp index 77f679ee71..36763b486e 100644 --- a/src/server/pegasus_server_write.cpp +++ b/src/server/pegasus_server_write.cpp @@ -17,7 +17,6 @@ * under the License. */ -#include #include #include #include diff --git a/src/server/result_writer.cpp b/src/server/result_writer.cpp index 4d3a9160e0..df78172e9c 100644 --- a/src/server/result_writer.cpp +++ b/src/server/result_writer.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include "pegasus/client.h" diff --git a/src/server/test/capacity_unit_calculator_test.cpp b/src/server/test/capacity_unit_calculator_test.cpp index 87309e6756..11ee1c706e 100644 --- a/src/server/test/capacity_unit_calculator_test.cpp +++ b/src/server/test/capacity_unit_calculator_test.cpp @@ -17,9 +17,8 @@ * under the License. */ -#include #include -#include +#include #include #include #include diff --git a/src/server/test/config.ini b/src/server/test/config.ini index d5a0d9aa31..45d9c310f1 100644 --- a/src/server/test/config.ini +++ b/src/server/test/config.ini @@ -37,8 +37,6 @@ toollets = profiler pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true [block_service.local_service] diff --git a/src/server/test/hashkey_transform_test.cpp b/src/server/test/hashkey_transform_test.cpp index 786e09ba79..5a8d8aa4b7 100644 --- a/src/server/test/hashkey_transform_test.cpp +++ b/src/server/test/hashkey_transform_test.cpp @@ -19,7 +19,6 @@ #include "server/hashkey_transform.h" -#include #include #include diff --git a/src/server/test/hotkey_collector_test.cpp b/src/server/test/hotkey_collector_test.cpp index 7219c5ca04..0d1cebdf01 100644 --- a/src/server/test/hotkey_collector_test.cpp +++ b/src/server/test/hotkey_collector_test.cpp @@ -17,7 +17,6 @@ #include "server/hotkey_collector.h" -#include #include #include #include diff --git a/src/server/test/pegasus_server_write_test.cpp b/src/server/test/pegasus_server_write_test.cpp index 72d21eb6a2..796570cc9b 100644 --- a/src/server/test/pegasus_server_write_test.cpp +++ b/src/server/test/pegasus_server_write_test.cpp @@ -17,9 +17,8 @@ * under the License. */ -#include #include -#include +#include #include #include #include diff --git a/src/server/test/pegasus_write_service_impl_test.cpp b/src/server/test/pegasus_write_service_impl_test.cpp index 0ac33faa40..a44a071055 100644 --- a/src/server/test/pegasus_write_service_impl_test.cpp +++ b/src/server/test/pegasus_write_service_impl_test.cpp @@ -17,12 +17,12 @@ * under the License. */ -#include #include -#include +#include #include #include #include +#include #include "gtest/gtest.h" #include "pegasus_key_schema.h" @@ -34,10 +34,8 @@ #include "server/rocksdb_wrapper.h" #include "utils/blob.h" #include "utils/fail_point.h" -#include -namespace pegasus { -namespace server { +namespace pegasus::server { class pegasus_write_service_impl_test : public pegasus_server_test_base { @@ -181,5 +179,4 @@ TEST_P(incr_test, incr_on_expire_record) db_get(req.key.to_string_view(), &get_ctx); ASSERT_TRUE(get_ctx.found); } -} // namespace server -} // namespace pegasus +} // namespace pegasus::server diff --git a/src/server/test/pegasus_write_service_test.cpp b/src/server/test/pegasus_write_service_test.cpp index e5c5b43828..cca8251c4c 100644 --- a/src/server/test/pegasus_write_service_test.cpp +++ b/src/server/test/pegasus_write_service_test.cpp @@ -17,10 +17,9 @@ * under the License. */ -#include #include #include -#include +#include #include #include #include diff --git a/src/server/test/rocksdb_wrapper_test.cpp b/src/server/test/rocksdb_wrapper_test.cpp index 7831afc713..cbf85c95fb 100644 --- a/src/server/test/rocksdb_wrapper_test.cpp +++ b/src/server/test/rocksdb_wrapper_test.cpp @@ -17,10 +17,10 @@ * under the License. */ -#include -#include +#include #include #include +#include #include #include "common/fs_manager.h" @@ -39,10 +39,8 @@ #include "utils/blob.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" -#include -namespace pegasus { -namespace server { +namespace pegasus::server { class rocksdb_wrapper_test : public pegasus_server_test_base { protected: @@ -232,5 +230,4 @@ TEST_P(rocksdb_wrapper_test, verify_timetag_compatible_with_version_0) _rocksdb_wrapper->_pegasus_data_version, std::move(get_ctx.raw_value), user_value); ASSERT_EQ(user_value.to_string(), value); } -} // namespace server -} // namespace pegasus +} // namespace pegasus::server diff --git a/src/shell/config.ini b/src/shell/config.ini index 8126688393..471a754fdb 100644 --- a/src/shell/config.ini +++ b/src/shell/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = false enable_default_app_mimic = true diff --git a/src/task/tests/async_call_test.cpp b/src/task/tests/async_call_test.cpp index ddc6172c02..bfbc3cad99 100644 --- a/src/task/tests/async_call_test.cpp +++ b/src/task/tests/async_call_test.cpp @@ -44,7 +44,6 @@ #include "task/task_code.h" #include "task/task_tracker.h" #include "utils/autoref_ptr.h" -#include "utils/enum_helper.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" #include "utils/thread_access_checker.h" diff --git a/src/test/bench_test/config.ini b/src/test/bench_test/config.ini index 371bb76ce7..2dc1331fcc 100644 --- a/src/test/bench_test/config.ini +++ b/src/test/bench_test/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/test/function_test/base_api/test_batch_get.cpp b/src/test/function_test/base_api/test_batch_get.cpp index ff0b15a2e2..1b8f243d70 100644 --- a/src/test/function_test/base_api/test_batch_get.cpp +++ b/src/test/function_test/base_api/test_batch_get.cpp @@ -18,10 +18,9 @@ */ // IWYU pragma: no_include -#include #include #include -#include +#include #include #include #include diff --git a/src/test/function_test/config.ini b/src/test/function_test/config.ini index ab405ae5b1..c9f4ea053c 100644 --- a/src/test/function_test/config.ini +++ b/src/test/function_test/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger enable_default_app_mimic = true diff --git a/src/test/kill_test/config.ini b/src/test/kill_test/config.ini index 0d7df1af15..3dfea2629a 100644 --- a/src/test/kill_test/config.ini +++ b/src/test/kill_test/config.ini @@ -36,8 +36,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/test/pressure_test/config-pressure.ini b/src/test/pressure_test/config-pressure.ini index a28381e14d..c72c875076 100644 --- a/src/test/pressure_test/config-pressure.ini +++ b/src/test/pressure_test/config-pressure.ini @@ -41,9 +41,6 @@ cli_remote = false start_nfs = false logging_start_level = LOG_LEVEL_INFO -logging_factory_name = dsn::tools::simple_logger -;logging_factory_name = dsn::tools::screen_logger -;logging_factory_name = dsn::tools::hpc_logger logging_flush_on_exit = true enable_default_app_mimic = true diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 337ac2591b..91ea0cc8ea 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -37,7 +37,8 @@ set(MY_PROJ_LIBS lz4 zstd snappy - absl::strings) + absl::strings + spdlog) # Extra files that will be installed set(MY_BINPLACES "") diff --git a/src/utils/api_utilities.h b/src/utils/api_utilities.h index ec0733ae5c..46af0df3c0 100644 --- a/src/utils/api_utilities.h +++ b/src/utils/api_utilities.h @@ -24,53 +24,13 @@ * THE SOFTWARE. */ -// Some useful utility functions for logging and mocking provided by rDSN. +// Some useful utility functions for mocking provided by rDSN. #pragma once -#include "utils/enum_helper.h" #include "utils/fmt_utils.h" #include "utils/ports.h" -/*! -@defgroup logging Logging Service -@ingroup service-api-utilities - - Logging Service - - Note developers can plug into rDSN their own logging libraryS - implementation, so as to integrate rDSN logs into - their own cluster operation systems. -@{ -*/ - -enum log_level_t -{ - LOG_LEVEL_DEBUG, - LOG_LEVEL_INFO, - LOG_LEVEL_WARNING, - LOG_LEVEL_ERROR, - LOG_LEVEL_FATAL, - LOG_LEVEL_COUNT, - LOG_LEVEL_INVALID -}; - -ENUM_BEGIN(log_level_t, LOG_LEVEL_INVALID) -ENUM_REG(LOG_LEVEL_DEBUG) -ENUM_REG(LOG_LEVEL_INFO) -ENUM_REG(LOG_LEVEL_WARNING) -ENUM_REG(LOG_LEVEL_ERROR) -ENUM_REG(LOG_LEVEL_FATAL) -ENUM_END(log_level_t) - -USER_DEFINED_ENUM_FORMATTER(log_level_t) - -// logs with level smaller than this start_level will not be logged -extern log_level_t log_start_level; -extern log_level_t get_log_start_level(); -extern void set_log_start_level(log_level_t level); -extern void global_log( - const char *file, const char *function, const int line, log_level_t log_level, const char *str); extern void dsn_coredump(); #define dreturn_not_ok_logged(err, ...) \ @@ -103,23 +63,3 @@ extern void dsn_coredump(); return false; \ } \ } while (0) - -#define dverify_logged(exp, level, ...) \ - do { \ - if (dsn_unlikely(!(exp))) { \ - LOG(level, __VA_ARGS__); \ - return false; \ - } \ - } while (0) - -#define dstop_on_false(exp) \ - if (dsn_unlikely(!(exp))) \ - return -#define dstop_on_false_logged(exp, level, ...) \ - do { \ - if (dsn_unlikely(!(exp))) { \ - LOG(level, __VA_ARGS__); \ - return; \ - } \ - } while (0) -/*@}*/ diff --git a/src/utils/enum_helper.h b/src/utils/enum_helper.h index b62918c534..a2fe8d4678 100644 --- a/src/utils/enum_helper.h +++ b/src/utils/enum_helper.h @@ -58,7 +58,8 @@ class enum_helper_xxx; #define ENUM_END2(type, name) \ return helper; \ } \ - inline type enum_from_string(const char *s, type invalid_value) \ + inline type enum_from_string(const char *s, \ + type invalid_value) /* NOLINT(misc-unused-parameters) */ \ { \ return ::dsn::enum_helper_xxx::instance(RegisterEnu_##name).parse(s); \ } \ diff --git a/src/utils/fmt_logging.h b/src/utils/fmt_logging.h index 97e751a48c..310193f8f2 100644 --- a/src/utils/fmt_logging.h +++ b/src/utils/fmt_logging.h @@ -19,28 +19,39 @@ #pragma once +#include +#include #include #include #include "utils/api_utilities.h" +#include "spdlog/common.h" +#include "spdlog/spdlog.h" +#include "utils/logging.h" -// The macros below no longer use the default snprintf method for log message formatting, -// instead we use fmt::format. -// TODO(wutao1): prevent construction of std::string for each log. +extern std::shared_ptr g_stderr_logger; +extern std::shared_ptr g_file_logger; -// __FILENAME__ macro comes from the cmake, in which we calculate a filename without path. #define LOG(level, ...) \ do { \ - if (level >= log_start_level) \ - global_log( \ - __FILENAME__, __FUNCTION__, __LINE__, level, fmt::format(__VA_ARGS__).c_str()); \ + const auto _lvl = (level); \ + g_stderr_logger->log( \ + spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, _lvl, __VA_ARGS__); \ + if (dsn_likely(!!g_file_logger)) { \ + g_file_logger->log( \ + spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, _lvl, __VA_ARGS__); \ + } \ } while (false) -#define LOG_DEBUG(...) LOG(LOG_LEVEL_DEBUG, __VA_ARGS__) -#define LOG_INFO(...) LOG(LOG_LEVEL_INFO, __VA_ARGS__) -#define LOG_WARNING(...) LOG(LOG_LEVEL_WARNING, __VA_ARGS__) -#define LOG_ERROR(...) LOG(LOG_LEVEL_ERROR, __VA_ARGS__) -#define LOG_FATAL(...) LOG(LOG_LEVEL_FATAL, __VA_ARGS__) +#define LOG_DEBUG(...) LOG(spdlog::level::debug, __VA_ARGS__) +#define LOG_INFO(...) LOG(spdlog::level::info, __VA_ARGS__) +#define LOG_WARNING(...) LOG(spdlog::level::warn, __VA_ARGS__) +#define LOG_ERROR(...) LOG(spdlog::level::err, __VA_ARGS__) +#define LOG_FATAL(...) \ + do { \ + LOG(spdlog::level::critical, __VA_ARGS__); \ + dsn_coredump(); \ + } while (false) #define LOG_WARNING_IF(x, ...) \ do { \ diff --git a/src/utils/logging.cpp b/src/utils/logging.cpp index 66aeeb8aef..12b98d8c8b 100644 --- a/src/utils/logging.cpp +++ b/src/utils/logging.cpp @@ -24,114 +24,233 @@ * THE SOFTWARE. */ -#include -#include +// IWYU pragma: no_include +#include +#include +// IWYU pragma: no_include +// IWYU pragma: no_include +#include +#include +#include +#include // IWYU pragma: keep +// IWYU pragma: no_include +// IWYU pragma: no_include +// IWYU pragma: no_include +#include +#include +#include #include #include #include +#include -#include "runtime/tool_api.h" -#include "simple_logger.h" -#include "utils/api_utilities.h" -#include "utils/factory_store.h" +#include "spdlog/common.h" +#include "spdlog/sinks/rotating_file_sink.h" +#include "spdlog/spdlog.h" +#include "task/task.h" +#include "task/task_worker.h" +#include "utils/command_manager.h" +#include "utils/enum_helper.h" #include "utils/flags.h" -#include "utils/fmt_logging.h" #include "utils/join_point.h" -#include "utils/logging_provider.h" +#include "utils/logging.h" +#include "utils/process_utils.h" #include "utils/sys_exit_hook.h" +#include "utils/threadpool_spec.h" + +enum log_level_t +{ + LOG_LEVEL_DEBUG, + LOG_LEVEL_INFO, + LOG_LEVEL_WARNING, + LOG_LEVEL_ERROR, + LOG_LEVEL_FATAL, + LOG_LEVEL_COUNT, + LOG_LEVEL_INVALID +}; + +ENUM_BEGIN(log_level_t, LOG_LEVEL_INVALID) +ENUM_REG(LOG_LEVEL_DEBUG) +ENUM_REG(LOG_LEVEL_INFO) +ENUM_REG(LOG_LEVEL_WARNING) +ENUM_REG(LOG_LEVEL_ERROR) +ENUM_REG(LOG_LEVEL_FATAL) +ENUM_END(log_level_t) DSN_DEFINE_string(core, logging_start_level, "LOG_LEVEL_INFO", "Logs with level larger than or equal to this level be logged"); +DSN_DEFINE_validator(logging_start_level, [](const char *value) -> bool { + const auto level = enum_from_string(value, LOG_LEVEL_INVALID); + return LOG_LEVEL_DEBUG <= level && level <= LOG_LEVEL_FATAL; +}); DSN_DEFINE_bool(core, logging_flush_on_exit, true, "Whether to flush the logs when the process exits"); -log_level_t log_start_level = LOG_LEVEL_INFO; +DSN_DEFINE_bool(tools.simple_logger, + short_header, + false, + "Whether to use short header (excluding " + "file, file number and function name " + "fields in each line)"); -namespace dsn { +DSN_DEFINE_bool(tools.simple_logger, fast_flush, false, "Whether to flush logs every second"); -using namespace tools; -DSN_REGISTER_COMPONENT_PROVIDER(screen_logger, "dsn::tools::screen_logger"); -DSN_REGISTER_COMPONENT_PROVIDER(simple_logger, "dsn::tools::simple_logger"); +DSN_DEFINE_uint64(tools.simple_logger, + max_log_file_bytes, + 64UL * 1024 * 1024, + "The maximum bytes of a log file. A new log file will be created if the current " + "log file exceeds this size."); +DSN_DEFINE_validator(max_log_file_bytes, [](int32_t value) -> bool { return value > 0; }); -std::function log_prefixed_message_func = []() -> std::string { return ": "; }; +DSN_DEFINE_uint64( + tools.simple_logger, + max_number_of_log_files_on_disk, + 20, + "The maximum number of log files to be reserved on disk, older logs are deleted automatically"); +DSN_DEFINE_validator(max_number_of_log_files_on_disk, + [](int32_t value) -> bool { return value > 0; }); -void set_log_prefixed_message_func(std::function func) -{ - log_prefixed_message_func = std::move(func); -} -} // namespace dsn +DSN_DEFINE_string(tools.simple_logger, base_name, "pegasus", "The default base name for log file"); + +DSN_DEFINE_string( + tools.simple_logger, + stderr_start_level, + "LOG_LEVEL_WARNING", + "The lowest level of log messages to be copied to stderr in addition to log files"); +DSN_DEFINE_validator(stderr_start_level, [](const char *value) -> bool { + const auto level = enum_from_string(value, LOG_LEVEL_INVALID); + return LOG_LEVEL_DEBUG <= level && level <= LOG_LEVEL_FATAL; +}); + +std::shared_ptr g_stderr_logger = spdlog::stderr_logger_mt("stderr"); +std::shared_ptr g_file_logger; + +static std::map to_spdlog_levels = { + {LOG_LEVEL_DEBUG, spdlog::level::debug}, + {LOG_LEVEL_INFO, spdlog::level::info}, + {LOG_LEVEL_WARNING, spdlog::level::warn}, + {LOG_LEVEL_ERROR, spdlog::level::err}, + {LOG_LEVEL_FATAL, spdlog::level::critical}}; static void log_on_sys_exit(::dsn::sys_exit_type) { - dsn::logging_provider *logger = dsn::logging_provider::instance(); - logger->flush(); + g_stderr_logger->flush(); + g_file_logger->flush(); } -void dsn_log_init(const std::string &logging_factory_name, - const std::string &log_dir, - const std::string &role_name, - const std::function &dsn_log_prefixed_message_func) +void dsn_log_init(const std::string &log_dir, const std::string &role_name) { - log_start_level = enum_from_string(FLAGS_logging_start_level, LOG_LEVEL_INVALID); + g_file_logger = spdlog::rotating_logger_mt( + "file", + fmt::format("{}/{}.log", log_dir, role_name.empty() ? FLAGS_base_name : role_name), + FLAGS_max_log_file_bytes, + FLAGS_max_number_of_log_files_on_disk, + true /*rotate_on_open*/); + // _symlink_path = utils::filesystem::path_combine(_log_dir, symlink_name); + const auto file_start_level = + to_spdlog_levels[enum_from_string(FLAGS_logging_start_level, LOG_LEVEL_INVALID)]; + g_file_logger->set_level(file_start_level); + g_file_logger->flush_on(spdlog::level::err); - CHECK_NE_MSG( - log_start_level, LOG_LEVEL_INVALID, "invalid [core] logging_start_level specified"); + const auto stderr_start_level = + to_spdlog_levels[enum_from_string(FLAGS_stderr_start_level, LOG_LEVEL_INVALID)]; + g_stderr_logger->set_level(stderr_start_level); + g_stderr_logger->flush_on(spdlog::level::err); + + if (FLAGS_fast_flush) { + spdlog::flush_every(std::chrono::seconds(1)); + } // register log flush on exit if (FLAGS_logging_flush_on_exit) { ::dsn::tools::sys_exit.put_back(log_on_sys_exit, "log.flush"); } - dsn::logging_provider *logger = dsn::utils::factory_store::create( - logging_factory_name.c_str(), dsn::PROVIDER_TYPE_MAIN, log_dir.c_str(), role_name.c_str()); - dsn::logging_provider::set_logger(logger); - - if (dsn_log_prefixed_message_func != nullptr) { - dsn::set_log_prefixed_message_func(dsn_log_prefixed_message_func); + // See: https://github.com/gabime/spdlog/wiki/3.-Custom-formatting#pattern-flags + auto formatter = std::make_unique(); + if (FLAGS_short_header) { + static const std::string kPattern = "%L%Y-%m-%d %H:%M:%S.%e %t %* %v"; + formatter->add_flag('*').set_pattern(kPattern); + } else { + static const std::string kPattern = "%L%Y-%m-%d %H:%M:%S.%e %t %* %s:%#:%!(): %v"; + formatter->add_flag('*').set_pattern(kPattern); } -} - -log_level_t get_log_start_level() { return log_start_level; } + spdlog::set_formatter(std::move(formatter)); -void set_log_start_level(log_level_t level) { log_start_level = level; } + ::dsn::command_manager::instance().add_global_cmd( + ::dsn::command_manager::instance().register_single_command( + "flush-log", + "Flush log to stderr or file", + "", + [](const std::vector & /*args*/) { + g_stderr_logger->flush(); + g_file_logger->flush(); + return "Flush done."; + })); -void global_log( - const char *file, const char *function, const int line, log_level_t log_level, const char *str) -{ - dsn::logging_provider *logger = dsn::logging_provider::instance(); - logger->log(file, function, line, log_level, str); + ::dsn::command_manager::instance().add_global_cmd( + ::dsn::command_manager::instance().register_single_command( + "reset-log-start-level", + "Reset the log start level", + "[DEBUG | INFO | WARNING | ERROR | FATAL]", + [](const std::vector &args) { + log_level_t start_level = LOG_LEVEL_INVALID; + if (args.empty()) { + start_level = enum_from_string(FLAGS_logging_start_level, LOG_LEVEL_INVALID); + } else { + std::string level_str = "LOG_LEVEL_" + args[0]; + start_level = enum_from_string(level_str.c_str(), LOG_LEVEL_INVALID); + if (start_level == LOG_LEVEL_INVALID) { + return "ERROR: invalid level '" + args[0] + "'"; + } + } + g_file_logger->set_level(to_spdlog_levels[start_level]); + return std::string("OK, current level is ") + enum_to_string(start_level); + })); } -namespace dsn { - -std::unique_ptr logging_provider::_logger; - -logging_provider *logging_provider::instance() +std::string log_prefixed_message_func() { - static std::unique_ptr default_logger(create_default_instance()); - return _logger ? _logger.get() : default_logger.get(); + const static thread_local int tid = dsn::utils::get_current_tid(); + const auto t = dsn::task::get_current_task_id(); + if (t != 0) { + if (nullptr != dsn::task::get_current_worker2()) { + return fmt::format("{}.{}{}.{:016}", + dsn::task::get_current_node_name(), + dsn::task::get_current_worker2()->pool_spec().name, + dsn::task::get_current_worker2()->index(), + t); + } + return fmt::format("{}.io-thrd.{}.{:016}", dsn::task::get_current_node_name(), tid, t); + } + + if (nullptr != dsn::task::get_current_worker2()) { + const static thread_local std::string prefix = + fmt::format("{}.{}{}", + dsn::task::get_current_node_name(), + dsn::task::get_current_worker2()->pool_spec().name, + dsn::task::get_current_worker2()->index()); + return prefix; + } + const static thread_local std::string prefix = + fmt::format("{}.io-thrd.{}", dsn::task::get_current_node_name(), tid); + return prefix; } -logging_provider *logging_provider::create_default_instance() +void pegasus_formatter_flag::format(const spdlog::details::log_msg &, + const std::tm &, + spdlog::memory_buf_t &dest) { - return new tools::screen_logger(nullptr, nullptr); + const auto prefix = log_prefixed_message_func(); + dest.append(prefix.data(), prefix.data() + prefix.size()); } -void logging_provider::set_logger(logging_provider *logger) { _logger.reset(logger); } - -namespace tools { -namespace internal_use_only { -bool register_component_provider(const char *name, - logging_provider::factory f, - ::dsn::provider_type type) +std::unique_ptr pegasus_formatter_flag::clone() const { - return dsn::utils::factory_store::register_factory(name, f, type); + return spdlog::details::make_unique(); } -} // namespace internal_use_only -} // namespace tools -} // namespace dsn diff --git a/src/utils/logging.h b/src/utils/logging.h new file mode 100644 index 0000000000..cadae5e025 --- /dev/null +++ b/src/utils/logging.h @@ -0,0 +1,42 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +#include +#include +#include + +namespace spdlog::details { +struct log_msg; +} // namespace spdlog::details +struct tm; + +// To keep the log format consistent with the existing log format, we need to print thread pool +// information in the log, spdlog use custom_flag_formatter to implement this feature. See +// https://github.com/gabime/spdlog/wiki/3.-Custom-formatting#extending-spdlog-with-your-own-flags. +class pegasus_formatter_flag : public spdlog::custom_flag_formatter +{ +public: + void + format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override; + [[nodiscard]] std::unique_ptr clone() const override; +}; + +extern void dsn_log_init(const std::string &log_dir, const std::string &role_name); diff --git a/src/utils/logging_provider.h b/src/utils/logging_provider.h deleted file mode 100644 index 264d721ce8..0000000000 --- a/src/utils/logging_provider.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include "utils/api_utilities.h" -#include "utils/command_manager.h" -#include "utils/factory_store.h" - -namespace dsn { - -/*! -@addtogroup tool-api-providers -@{ -*/ -class logging_provider -{ -public: - template - static logging_provider *create(const char *log_dir, const char *role_name) - { - return new T(log_dir, role_name); - } - - typedef logging_provider *(*factory)(const char *, const char *); - -public: - virtual ~logging_provider() = default; - - // singleton - static logging_provider *instance(); - - // not thread-safe - static void set_logger(logging_provider *logger); - - virtual void log(const char *file, - const char *function, - const int line, - log_level_t log_level, - const char *str) = 0; - - virtual void flush() = 0; - -protected: - static std::unique_ptr _logger; - - static logging_provider *create_default_instance(); - - logging_provider(log_level_t stderr_start_level) : _stderr_start_level(stderr_start_level) {} - - const log_level_t _stderr_start_level; -}; - -void set_log_prefixed_message_func(std::function func); -extern std::function log_prefixed_message_func; - -namespace tools { -namespace internal_use_only { -bool register_component_provider(const char *name, - logging_provider::factory f, - ::dsn::provider_type type); -} // namespace internal_use_only -} // namespace tools -} // namespace dsn - -extern void dsn_log_init(const std::string &logging_factory_name, - const std::string &log_dir, - const std::string &role_name, - const std::function &dsn_log_prefixed_message_func); diff --git a/src/utils/simple_logger.cpp b/src/utils/simple_logger.cpp deleted file mode 100644 index 881b97ecd8..0000000000 --- a/src/utils/simple_logger.cpp +++ /dev/null @@ -1,427 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "utils/simple_logger.h" - -#include -// IWYU pragma: no_include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "runtime/api_layer1.h" -#include "utils/command_manager.h" -#include "utils/errors.h" -#include "utils/fail_point.h" -#include "utils/filesystem.h" -#include "utils/flags.h" -#include "utils/fmt_logging.h" -#include "utils/ports.h" -#include "utils/process_utils.h" -#include "utils/safe_strerror_posix.h" -#include "utils/string_conv.h" -#include "utils/strings.h" -#include "utils/time_utils.h" - -DSN_DEFINE_uint64(tools.simple_logger, - max_log_file_bytes, - 64 * 1024 * 1024, - "The maximum bytes of a log file. A new log file will be created if the current " - "log file exceeds this size."); -DSN_DEFINE_validator(max_log_file_bytes, [](int32_t value) -> bool { return value > 0; }); - -DSN_DEFINE_bool(tools.simple_logger, fast_flush, false, "Whether to flush logs immediately"); -DSN_DEFINE_bool(tools.simple_logger, - short_header, - false, - "Whether to use short header (excluding " - "file, file number and function name " - "fields in each line)"); - -DSN_DEFINE_uint64( - tools.simple_logger, - max_number_of_log_files_on_disk, - 20, - "The maximum number of log files to be reserved on disk, older logs are deleted automatically"); -DSN_DEFINE_validator(max_number_of_log_files_on_disk, - [](int32_t value) -> bool { return value > 0; }); - -DSN_DEFINE_string(tools.screen_logger, - stderr_start_level_on_stdout, - "LOG_LEVEL_WARNING", - "The lowest level of log messages to be copied to stderr in addition to stdout"); -DSN_DEFINE_validator(stderr_start_level_on_stdout, [](const char *value) -> bool { - const auto level = enum_from_string(value, LOG_LEVEL_INVALID); - return LOG_LEVEL_DEBUG <= level && level <= LOG_LEVEL_FATAL; -}); - -DSN_DEFINE_string( - tools.simple_logger, - stderr_start_level, - "LOG_LEVEL_WARNING", - "The lowest level of log messages to be copied to stderr in addition to log files"); -DSN_DEFINE_validator(stderr_start_level, [](const char *value) -> bool { - const auto level = enum_from_string(value, LOG_LEVEL_INVALID); - return LOG_LEVEL_DEBUG <= level && level <= LOG_LEVEL_FATAL; -}); - -DSN_DEFINE_string(tools.simple_logger, base_name, "pegasus", "The default base name for log file"); - -DSN_DECLARE_string(logging_start_level); - -namespace dsn { -namespace tools { -namespace { -int print_header(FILE *fp, log_level_t stderr_start_level, log_level_t log_level) -{ - // The leading character of each log line, corresponding to the log level - // D: Debug - // I: Info - // W: Warning - // E: Error - // F: Fatal - static char s_level_char[] = "DIWEF"; - - uint64_t ts = dsn_now_ns(); - std::string time_str; - dsn::utils::time_ms_to_string(ts / 1000000, time_str); - - int tid = dsn::utils::get_current_tid(); - const auto header = fmt::format( - "{}{} ({} {}) {}", s_level_char[log_level], time_str, ts, tid, log_prefixed_message_func()); - const int written_size = fmt::fprintf(fp, "%s", header.c_str()); - if (log_level >= stderr_start_level) { - fmt::fprintf(stderr, "%s", header.c_str()); - } - return written_size; -} - -int print_long_header(FILE *fp, - const char *file, - const char *function, - const int line, - bool short_header, - log_level_t stderr_start_level, - log_level_t log_level) -{ - if (short_header) { - return 0; - } - - const auto long_header = fmt::format("{}:{}:{}(): ", file, line, function); - const int written_size = fmt::fprintf(fp, "%s", long_header.c_str()); - if (log_level >= stderr_start_level) { - fmt::fprintf(stderr, "%s", long_header.c_str()); - } - return written_size; -} - -int print_body(FILE *fp, const char *body, log_level_t stderr_start_level, log_level_t log_level) -{ - const int written_size = fmt::fprintf(fp, "%s\n", body); - if (log_level >= stderr_start_level) { - fmt::fprintf(stderr, "%s\n", body); - } - return written_size; -} - -inline void process_fatal_log(log_level_t log_level) -{ - if (dsn_likely(log_level < LOG_LEVEL_FATAL)) { - return; - } - - bool coredump = true; - FAIL_POINT_INJECT_NOT_RETURN_F("coredump_for_fatal_log", [&coredump](std::string_view str) { - CHECK(buf2bool(str, coredump), - "invalid coredump toggle for fatal log, should be true or false: {}", - str); - }); - - if (dsn_likely(coredump)) { - dsn_coredump(); - } -} - -} // anonymous namespace - -screen_logger::screen_logger(const char *, const char *) - : logging_provider(enum_from_string(FLAGS_stderr_start_level_on_stdout, LOG_LEVEL_INVALID)), - _short_header(true) -{ -} - -void screen_logger::print_header(log_level_t log_level) -{ - ::dsn::tools::print_header(stdout, _stderr_start_level, log_level); -} - -void screen_logger::print_long_header(const char *file, - const char *function, - const int line, - log_level_t log_level) -{ - ::dsn::tools::print_long_header( - stdout, file, function, line, _short_header, _stderr_start_level, log_level); -} - -void screen_logger::print_body(const char *body, log_level_t log_level) -{ - ::dsn::tools::print_body(stdout, body, _stderr_start_level, log_level); -} - -void screen_logger::log( - const char *file, const char *function, const int line, log_level_t log_level, const char *str) -{ - utils::auto_lock<::dsn::utils::ex_lock_nr> l(_lock); - - print_header(log_level); - print_long_header(file, function, line, log_level); - print_body(str, log_level); - if (log_level >= LOG_LEVEL_ERROR) { - ::fflush(stdout); - } - - process_fatal_log(log_level); -} - -void screen_logger::flush() { ::fflush(stdout); } - -simple_logger::simple_logger(const char *log_dir, const char *role_name) - : logging_provider(enum_from_string(FLAGS_stderr_start_level, LOG_LEVEL_INVALID)), - _log_dir(std::string(log_dir)), - _log(nullptr), - _file_bytes(0) -{ - // Use 'role_name' if it is specified, otherwise use 'base_name'. - const std::string symlink_name( - fmt::format("{}.log", utils::is_empty(role_name) ? FLAGS_base_name : role_name)); - _file_name_prefix = fmt::format("{}.", symlink_name); - _symlink_path = utils::filesystem::path_combine(_log_dir, symlink_name); - - create_log_file(); - - static std::once_flag flag; - std::call_once(flag, [&]() { - ::dsn::command_manager::instance().add_global_cmd( - ::dsn::command_manager::instance().register_single_command( - "flush-log", - "Flush log to stderr or file", - "", - [this](const std::vector &args) { - this->flush(); - return "Flush done."; - })); - - ::dsn::command_manager::instance().add_global_cmd( - ::dsn::command_manager::instance().register_single_command( - "reset-log-start-level", - "Reset the log start level", - "[DEBUG | INFO | WARNING | ERROR | FATAL]", - [](const std::vector &args) { - log_level_t start_level; - if (args.size() == 0) { - start_level = - enum_from_string(FLAGS_logging_start_level, LOG_LEVEL_INVALID); - } else { - std::string level_str = "LOG_LEVEL_" + args[0]; - start_level = enum_from_string(level_str.c_str(), LOG_LEVEL_INVALID); - if (start_level == LOG_LEVEL_INVALID) { - return "ERROR: invalid level '" + args[0] + "'"; - } - } - set_log_start_level(start_level); - return std::string("OK, current level is ") + enum_to_string(start_level); - })); - }); -} - -void simple_logger::create_log_file() -{ - // Close the current log file if it is opened. - if (_log != nullptr) { - ::fclose(_log); - _log = nullptr; - } - - // Reset the file size. - _file_bytes = 0; - - // Open the new log file. - uint64_t ts = dsn::utils::get_current_physical_time_ns(); - std::string time_str; - ::dsn::utils::time_ms_to_sequent_string(ts / 1000000, time_str); - const std::string file_name(fmt::format("{}{}", _file_name_prefix, time_str)); - const std::string path(utils::filesystem::path_combine(_log_dir, file_name)); - _log = ::fopen(path.c_str(), "w+"); - CHECK_NOTNULL(_log, "Failed to fopen {}: {}", path, dsn::utils::safe_strerror(errno)); - - // Unlink the latest log file. - if (::unlink(_symlink_path.c_str()) != 0) { - if (errno != ENOENT) { - fmt::print(stderr, - "Failed to unlink {}: {}\n", - _symlink_path, - dsn::utils::safe_strerror(errno)); - } - } - - // Create a new symlink to the newly created log file. - if (::symlink(file_name.c_str(), _symlink_path.c_str()) != 0) { - fmt::print(stderr, - "Failed to symlink {} as {}: {}\n", - file_name, - _symlink_path, - dsn::utils::safe_strerror(errno)); - } - - // Remove redundant log files. - remove_redundant_files(); -} - -void simple_logger::remove_redundant_files() -{ - // Collect log files. - const auto file_path_pattern = - fmt::format("{}*", utils::filesystem::path_combine(_log_dir, _file_name_prefix)); - std::vector matching_files; - const auto es = dsn::utils::filesystem::glob(file_path_pattern, matching_files); - if (!es) { - fmt::print( - stderr, "{}: Failed to glob '{}', error \n", es.description(), file_path_pattern); - return; - } - - // Skip if the number of log files is not exceeded. - auto max_matches = static_cast(FLAGS_max_number_of_log_files_on_disk); - if (matching_files.size() <= max_matches) { - return; - } - - // Collect mtimes of log files. - std::vector> matching_file_mtimes; - for (auto &matching_file_path : matching_files) { - struct stat s; - if (::stat(matching_file_path.c_str(), &s) != 0) { - fmt::print(stderr, - "Failed to stat {}: {}\n", - matching_file_path, - dsn::utils::safe_strerror(errno)); - continue; - } - -#ifdef __APPLE__ - int64_t mtime = s.st_mtimespec.tv_sec * 1000000 + s.st_mtimespec.tv_nsec / 1000; -#else - int64_t mtime = s.st_mtim.tv_sec * 1000000 + s.st_mtim.tv_nsec / 1000; -#endif - matching_file_mtimes.emplace_back(mtime, std::move(matching_file_path)); - } - - // Use mtime to determine which matching files to delete. This could - // potentially be ambiguous, depending on the resolution of last-modified - // timestamp in the filesystem, but that is part of the contract. - std::sort(matching_file_mtimes.begin(), matching_file_mtimes.end()); - matching_file_mtimes.resize(matching_file_mtimes.size() - max_matches); - - // Remove redundant log files. - for (const auto &[_, matching_file] : matching_file_mtimes) { - if (::remove(matching_file.c_str()) != 0) { - // If remove failed, just print log and ignore it. - fmt::print(stderr, - "Failed to remove redundant log file {}: {}\n", - matching_file, - dsn::utils::safe_strerror(errno)); - } - } -} - -simple_logger::~simple_logger() -{ - utils::auto_lock<::dsn::utils::ex_lock> l(_lock); - ::fclose(_log); - _log = nullptr; -} - -void simple_logger::flush() -{ - utils::auto_lock<::dsn::utils::ex_lock> l(_lock); - ::fflush(_log); - ::fflush(stderr); - ::fflush(stdout); -} - -void simple_logger::print_header(log_level_t log_level) -{ - add_bytes_if_valid(::dsn::tools::print_header(_log, _stderr_start_level, log_level)); -} - -void simple_logger::print_long_header(const char *file, - const char *function, - const int line, - log_level_t log_level) -{ - add_bytes_if_valid(::dsn::tools::print_long_header( - _log, file, function, line, FLAGS_short_header, _stderr_start_level, log_level)); -} - -void simple_logger::print_body(const char *body, log_level_t log_level) -{ - add_bytes_if_valid(::dsn::tools::print_body(_log, body, _stderr_start_level, log_level)); -} - -void simple_logger::log( - const char *file, const char *function, const int line, log_level_t log_level, const char *str) -{ - utils::auto_lock<::dsn::utils::ex_lock> l(_lock); - - CHECK_NOTNULL(_log, "Log file hasn't been initialized yet"); - print_header(log_level); - print_long_header(file, function, line, log_level); - print_body(str, log_level); - if (FLAGS_fast_flush || log_level >= LOG_LEVEL_ERROR) { - ::fflush(_log); - } - - process_fatal_log(log_level); - - if (_file_bytes >= FLAGS_max_log_file_bytes) { - create_log_file(); - } -} - -} // namespace tools -} // namespace dsn diff --git a/src/utils/simple_logger.h b/src/utils/simple_logger.h deleted file mode 100644 index 5437c0fe6a..0000000000 --- a/src/utils/simple_logger.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include -#include -#include - -#include "utils/api_utilities.h" -#include "utils/logging_provider.h" -#include "utils/ports.h" -#include "utils/synchronize.h" - -namespace dsn { -namespace tools { - -/* - * screen_logger provides a logger which writes to terminal. - */ -class screen_logger : public logging_provider -{ -public: - explicit screen_logger(const char *, const char *); - ~screen_logger() override = default; - - void log(const char *file, - const char *function, - const int line, - log_level_t log_level, - const char *str) override; - - virtual void flush(); - -private: - void print_header(log_level_t log_level); - void print_long_header(const char *file, - const char *function, - const int line, - log_level_t log_level); - void print_body(const char *body, log_level_t log_level); - - ::dsn::utils::ex_lock_nr _lock; - const bool _short_header; -}; - -/* - * simple_logger provides a logger which writes to file. - * The max number of lines in a logger file is 200000. - */ -class simple_logger : public logging_provider -{ -public: - // 'log_dir' is the directory to store log files, 'role_name' is the name of the process, - // such as 'replica_server', 'meta_server' in Pegasus. - simple_logger(const char *log_dir, const char *role_name); - ~simple_logger() override; - - void log(const char *file, - const char *function, - const int line, - log_level_t log_level, - const char *str) override; - - void flush() override; - -private: - void print_header(log_level_t log_level); - void print_long_header(const char *file, - const char *function, - const int line, - log_level_t log_level); - void print_body(const char *body, log_level_t log_level); - - inline void add_bytes_if_valid(int bytes) - { - if (dsn_likely(bytes > 0)) { - _file_bytes += static_cast(bytes); - } - } - - void create_log_file(); - void remove_redundant_files(); - -private: - ::dsn::utils::ex_lock _lock; // use recursive lock to avoid dead lock when flush() is called - // in signal handler if cored for bad logging format reason. - // The directory to store log files. - const std::string _log_dir; - // The path of the symlink to the latest log file. - std::string _symlink_path; - // The prefix of the log file names. The actual log files are prefixed by '_file_name_prefix' - // and postfixed by timestamp. - std::string _file_name_prefix; - // The current log file descriptor. - FILE *_log; - // The byte size of the current log file. - uint64_t _file_bytes; -}; -} // namespace tools -} // namespace dsn diff --git a/src/utils/test/CMakeLists.txt b/src/utils/test/CMakeLists.txt index 8502cabb76..1477a4ee18 100644 --- a/src/utils/test/CMakeLists.txt +++ b/src/utils/test/CMakeLists.txt @@ -42,8 +42,9 @@ set(MY_PROJ_LIBS set(MY_BOOST_LIBS Boost::system Boost::filesystem) -# Extra files that will be installed -set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini" +set(MY_BINPLACES + "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-dup-key.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-dup-section.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-empty.ini" @@ -53,8 +54,7 @@ set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-sample.ini" "${CMAKE_CURRENT_SOURCE_DIR}/config-unmatch-section.ini" "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" - ) + "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh") add_subdirectory(nth_element_bench) add_definitions(-Wno-dangling-else) dsn_add_test() diff --git a/src/utils/test/config.ini b/src/utils/test/config.ini new file mode 100644 index 0000000000..4d9321d411 --- /dev/null +++ b/src/utils/test/config.ini @@ -0,0 +1,27 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you 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. + +[apps.mimic] +type = dsn.app.mimic +pools = THREAD_POOL_TEST_SERVER + +[core] +enable_default_app_mimic = true +tool = nativerun + +[test] +logging_test_simple_benchmark_loops = 10 \ No newline at end of file diff --git a/src/utils/test/endian_test.cpp b/src/utils/test/endian_test.cpp index dd8a807c66..73a0ebb2bf 100644 --- a/src/utils/test/endian_test.cpp +++ b/src/utils/test/endian_test.cpp @@ -21,9 +21,8 @@ #include "gtest/gtest.h" #include "utils/endians.h" -#include "utils/enum_helper.h" -using namespace dsn; +namespace dsn { TEST(endian, conversion) { @@ -72,3 +71,4 @@ TEST(endian, write_and_read) } } } +} // namespace dsn diff --git a/src/utils/test/logger.cpp b/src/utils/test/logger.cpp deleted file mode 100644 index a06d85ef18..0000000000 --- a/src/utils/test/logger.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Microsoft Corporation - * - * -=- Robust Distributed System Nucleus (rDSN) -=- - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gtest/gtest.h" -#include "gutil/map_util.h" -#include "utils/api_utilities.h" -#include "utils/filesystem.h" -#include "utils/flags.h" -#include "utils/simple_logger.h" -#include "utils/test_macros.h" - -DSN_DECLARE_uint64(max_number_of_log_files_on_disk); - -namespace dsn { -namespace tools { -class logger_test : public testing::Test -{ -public: - void SetUp() override - { - std::string cwd; - ASSERT_TRUE(dsn::utils::filesystem::get_current_directory(cwd)); - // NOTE: Don't name the dir with "test", otherwise the whole utils test dir would be - // removed. - test_dir = dsn::utils::filesystem::path_combine(cwd, "logger_test"); - - NO_FATALS(prepare_test_dir()); - std::set files; - NO_FATALS(get_log_files(files)); - NO_FATALS(clear_files(files)); - } - - void get_log_files(std::set &file_names) - { - std::vector sub_list; - ASSERT_TRUE(utils::filesystem::get_subfiles(test_dir, sub_list, false)); - - file_names.clear(); - std::regex pattern(R"(SimpleLogger\.log\.[0-9]{8}_[0-9]{6}_[0-9]{3})"); - for (const auto &path : sub_list) { - std::string name(utils::filesystem::get_file_name(path)); - if (std::regex_match(name, pattern)) { - ASSERT_TRUE(gutil::InsertIfNotPresent(&file_names, name)); - } - } - } - - void compare_log_files(const std::set &before_files, - const std::set &after_files) - { - ASSERT_FALSE(after_files.empty()); - - // One new log file is created. - if (after_files.size() == before_files.size() + 1) { - // All the file names are the same. - for (auto it1 = before_files.begin(), it2 = after_files.begin(); - it1 != before_files.end(); - ++it1, ++it2) { - ASSERT_EQ(*it1, *it2); - } - // The number of log files is the same, but they have rolled. - } else if (after_files.size() == before_files.size()) { - auto it1 = before_files.begin(); - auto it2 = after_files.begin(); - // The first file is different, the one in 'before_files' is older. - ASSERT_NE(*it1, *it2); - - // The rest of the files are the same. - for (++it1; it1 != before_files.end(); ++it1, ++it2) { - ASSERT_EQ(*it1, *it2); - } - } else { - ASSERT_TRUE(false) << "Invalid number of log files, before=" << before_files.size() - << ", after=" << after_files.size(); - } - } - - void clear_files(const std::set &file_names) - { - for (const auto &file_name : file_names) { - ASSERT_TRUE(dsn::utils::filesystem::remove_path(file_name)); - } - } - - void prepare_test_dir() - { - ASSERT_TRUE(dsn::utils::filesystem::create_directory(test_dir)) << test_dir; - } - - void remove_test_dir() - { - ASSERT_TRUE(dsn::utils::filesystem::remove_path(test_dir)) << test_dir; - } - -public: - std::string test_dir; -}; - -#define LOG_PRINT(logger, ...) \ - (logger)->log( \ - __FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_DEBUG, fmt::format(__VA_ARGS__).c_str()) - -TEST_F(logger_test, screen_logger_test) -{ - auto logger = std::make_unique(nullptr, nullptr); - LOG_PRINT(logger.get(), "{}", "test_print"); - std::thread t([](screen_logger *lg) { LOG_PRINT(lg, "{}", "test_print"); }, logger.get()); - t.join(); - logger->flush(); -} - -TEST_F(logger_test, redundant_log_test) -{ - // Create redundant log files to test if their number could be restricted. - for (unsigned int i = 0; i < FLAGS_max_number_of_log_files_on_disk + 10; ++i) { - std::set before_files; - NO_FATALS(get_log_files(before_files)); - - auto logger = std::make_unique(test_dir.c_str(), "SimpleLogger"); - for (unsigned int i = 0; i != 1000; ++i) { - LOG_PRINT(logger.get(), "{}", "test_print"); - } - logger->flush(); - - std::set after_files; - NO_FATALS(get_log_files(after_files)); - NO_FATALS(compare_log_files(before_files, after_files)); - ::usleep(2000); - } - - std::set files; - NO_FATALS(get_log_files(files)); - ASSERT_FALSE(files.empty()); - ASSERT_EQ(FLAGS_max_number_of_log_files_on_disk, files.size()); -} - -} // namespace tools -} // namespace dsn diff --git a/src/utils/test/logging.cpp b/src/utils/test/logging.cpp index 64eccf29e2..e73da3a5aa 100644 --- a/src/utils/test/logging.cpp +++ b/src/utils/test/logging.cpp @@ -24,74 +24,81 @@ * THE SOFTWARE. */ -#include +#include +#include #include -#include #include "gtest/gtest.h" -#include "utils/api_utilities.h" -#include "utils/fail_point.h" +#include "spdlog/common.h" +#include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/timer.h" -TEST(LoggingTest, GlobalLog) -{ - std::cout << "logging start level = " << enum_to_string(get_log_start_level()) << std::endl; - global_log(__FILENAME__, __FUNCTION__, __LINE__, LOG_LEVEL_INFO, "in TEST(core, logging)"); -} +TEST(LoggingTest, LOG) { LOG(spdlog::level::info, "in TEST(LoggingTest, GlobalLog)"); } + +DSN_DEFINE_int32(test, + logging_test_simple_benchmark_loops, + 10, + "The loop times for LoggingTest.SimpleBenchmark test case"); -TEST(LoggingTest, GlobalLogBig) +TEST(LoggingTest, LOGWithBigString) { std::string big_str(128000, 'x'); - global_log(__FILENAME__, __FUNCTION__, __LINE__, LOG_LEVEL_INFO, big_str.c_str()); + LOG(spdlog::level::info, big_str.c_str()); } TEST(LoggingTest, LogMacro) { - struct test_case - { - log_level_t level; - std::string str; - } tests[] = {{LOG_LEVEL_DEBUG, "This is a test"}, - {LOG_LEVEL_DEBUG, "\\x00%d\\x00\\x01%n/nm"}, - {LOG_LEVEL_INFO, "\\x00%d\\x00\\x01%n/nm"}, - {LOG_LEVEL_WARNING, "\\x00%d\\x00\\x01%n/nm"}, - {LOG_LEVEL_ERROR, "\\x00%d\\x00\\x01%n/nm"}, - {LOG_LEVEL_FATAL, "\\x00%d\\x00\\x01%n/nm"}}; - - dsn::fail::setup(); - dsn::fail::cfg("coredump_for_fatal_log", "void(false)"); + std::string str1 = "This is a test"; + std::string str2 = R"(\x00%d\x00\x01%n/nm)"; - for (auto test : tests) { - // Test logging_provider::log. - LOG(test.level, "LOG: sortkey = {}", test.str); - } - - dsn::fail::teardown(); + LOG_DEBUG("LOG: sortkey = {}", str1); + LOG_DEBUG("LOG: sortkey = {}", str2); + LOG_INFO("LOG: sortkey = {}", str2); + LOG_WARNING("LOG: sortkey = {}", str2); + LOG_ERROR("LOG: sortkey = {}", str2); + ASSERT_DEATH(LOG_FATAL("LOG: sortkey = {}", str2), "LOG: sortkey ="); } TEST(LoggingTest, TestLogTiming) { - LOG_TIMING_PREFIX_IF(INFO, true, "prefix", "foo test{}", 0) {} - LOG_TIMING_IF(INFO, true, "no_prefix foo test{}", 1) {} - LOG_TIMING_PREFIX(INFO, "prefix", "foo test{}", 2) {} - LOG_TIMING(INFO, "foo test{}", 3){} + LOG_INFO("common info log"); + LOG_TIMING_PREFIX_IF(info, true, "prefix", "foo test{}", 0) {} + LOG_TIMING_IF(info, true, "no_prefix foo test{}", 1) {} + LOG_TIMING_PREFIX(info, "prefix", "foo test{}", 2) {} + LOG_TIMING(info, "foo test{}", 3){} { - SCOPED_LOG_TIMING(INFO, "bar {}", 0); - SCOPED_LOG_SLOW_EXECUTION(INFO, 1, "bar {}", 1); - SCOPED_LOG_SLOW_EXECUTION_PREFIX(INFO, 1, "prefix", "bar {}", 1); + SCOPED_LOG_TIMING(info, "bar {}", 0); + SCOPED_LOG_SLOW_EXECUTION(info, 1, "bar {}", 1); + SCOPED_LOG_SLOW_EXECUTION_PREFIX(info, 1, "prefix", "bar {}", 1); } - LOG_SLOW_EXECUTION(INFO, 1, "baz {}", 0) {} + LOG_SLOW_EXECUTION(info, 1, "baz {}", 0) {} // Previous implementations of the above macro confused clang-tidy's use-after-move // check and generated false positives. std::string s1 = "hello"; std::string s2; - LOG_SLOW_EXECUTION(INFO, 1, "baz") + LOG_SLOW_EXECUTION(info, 1, "baz") { LOG_INFO(s1); - s2 = std::move(s1); + s2 = s1; } + LOG_INFO("common info log"); ASSERT_EQ("hello", s2); } + +TEST(LoggingTest, SimpleBenchmark) +{ + g_stderr_logger->set_level(spdlog::level::critical); + g_file_logger->set_level(spdlog::level::debug); + SCOPED_LOG_TIMING(info, + "LoggingTest.SimpleBenchmark loop {} times", + FLAGS_logging_test_simple_benchmark_loops); + for (int i = 0; i < FLAGS_logging_test_simple_benchmark_loops; i++) { + LOG_DEBUG("abc {}, {}, {}", i, 1.0, "hello 1"); + LOG_INFO("abc {}, {}, {}", i + 1, 2.0, "hello 2"); + LOG_WARNING("abc {}, {}, {}", i + 2, 3.0, "hello 3"); + LOG_ERROR("abc {}, {}, {}", i + 3, 4.0, "hello 4"); + } +} diff --git a/src/utils/test/main.cpp b/src/utils/test/main.cpp index 0bdfb7f7a5..ddf8432723 100644 --- a/src/utils/test/main.cpp +++ b/src/utils/test/main.cpp @@ -18,16 +18,15 @@ #include #include +#include "runtime/app_model.h" #include "utils/flags.h" -#include "utils/logging_provider.h" +#include "utils/logging.h" GTEST_API_ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); - - dsn_log_init("dsn::tools::simple_logger", "./", "test", nullptr); - + dsn_log_init("./", "test"); + dsn_run_config("config.ini", false); dsn::flags_initialize(); - return RUN_ALL_TESTS(); } diff --git a/src/utils/timer.h b/src/utils/timer.h index ee5113ac73..dc92558c5a 100644 --- a/src/utils/timer.h +++ b/src/utils/timer.h @@ -22,12 +22,14 @@ #include "utils/api_utilities.h" #include "utils/chrono_literals.h" #include "utils/fmt_logging.h" +#include "spdlog/common.h" +#include "spdlog/spdlog.h" /// These macros are inspired by Apache Kudu /// https://github.com/apache/kudu/blob/1.17.0/src/kudu/util/stopwatch.h. // Macro for logging timing of a block. Usage: -// LOG_TIMING_PREFIX_IF(INFO, FLAGS_should_record_time, "Tablet X: ", "doing some task") { +// LOG_TIMING_PREFIX_IF(info, FLAGS_should_record_time, "Tablet X: ", "doing some task") { // ... some task which takes some time // } // If FLAGS_should_record_time is true, yields a log like: @@ -39,7 +41,7 @@ for (dsn::timer_internal::LogTiming _l(__FILENAME__, \ __FUNCTION__, \ __LINE__, \ - LOG_LEVEL_##severity, \ + spdlog::level::severity, \ prefix, \ fmt::format(__VA_ARGS__), \ -1, \ @@ -63,7 +65,7 @@ dsn::timer_internal::LogTiming VARNAME_LINENUM(_log_timing)(__FILENAME__, \ __FUNCTION__, \ __LINE__, \ - LOG_LEVEL_##severity, \ + spdlog::level::severity, \ "", \ fmt::format(__VA_ARGS__), \ -1, \ @@ -74,7 +76,7 @@ dsn::timer_internal::LogTiming VARNAME_LINENUM(_log_timing)(__FILENAME__, \ __FUNCTION__, \ __LINE__, \ - LOG_LEVEL_##severity, \ + spdlog::level::severity, \ "", \ fmt::format(__VA_ARGS__), \ max_expected_millis, \ @@ -85,14 +87,14 @@ dsn::timer_internal::LogTiming VARNAME_LINENUM(_log_timing)(__FILENAME__, \ __FUNCTION__, \ __LINE__, \ - LOG_LEVEL_##severity, \ + spdlog::level::severity, \ prefix, \ fmt::format(__VA_ARGS__), \ max_expected_millis, \ true) // Macro for logging timing of a block. Usage: -// LOG_SLOW_EXECUTION(INFO, 5, "doing some task") { +// LOG_SLOW_EXECUTION(info, 5, "doing some task") { // ... some task which takes some time // } // when slower than 5 milliseconds, yields a log like: @@ -102,7 +104,7 @@ for (dsn::timer_internal::LogTiming _l(__FILENAME__, \ __FUNCTION__, \ __LINE__, \ - LOG_LEVEL_##severity, \ + spdlog::level::severity, \ "", \ fmt::format(__VA_ARGS__), \ max_expected_millis, \ @@ -158,7 +160,7 @@ class LogTiming LogTiming(const char *file, const char *function, int line, - log_level_t severity, + spdlog::level::level_enum severity, std::string prefix, std::string description, int64_t max_expected_millis, @@ -196,7 +198,7 @@ class LogTiming const char *file_; const char *function_; const int line_; - const log_level_t severity_; + const spdlog::level::level_enum severity_; const std::string prefix_; const std::string description_; const int64_t max_expected_millis_; @@ -210,15 +212,12 @@ class LogTiming stopwatch_.stop(); auto ms = stopwatch_.m_elapsed(); if (max_expected_millis < 0 || ms.count() > max_expected_millis) { - global_log(file_, - function_, - line_, - severity_, - fmt::format("{}ime spent {}: {}ms", - prefix_.empty() ? "T" : fmt::format("{} t", prefix_), - description_, - ms.count()) - .c_str()); + spdlog::log(spdlog::source_loc{file_, line_, function_}, + severity_, + "{}ime spent {}: {}ms", + prefix_.empty() ? "T" : fmt::format("{} t", prefix_), + description_, + ms.count()); } } }; diff --git a/src/zookeeper/test/config-test.ini b/src/zookeeper/test/config-test.ini index 5a07160aef..7457143bfc 100644 --- a/src/zookeeper/test/config-test.ini +++ b/src/zookeeper/test/config-test.ini @@ -63,7 +63,6 @@ tool = nativerun pause_on_start = false logging_start_level = LOG_LEVEL_DEBUG -logging_factory_name = dsn::tools::simple_logger [tools.simple_logger]