Skip to content

Commit

Permalink
feat(logging): Use spdlog to replace simple_logger and screen_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Aug 2, 2024
1 parent 581a811 commit 25ef5db
Show file tree
Hide file tree
Showing 134 changed files with 340 additions and 1,227 deletions.
4 changes: 0 additions & 4 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ header:
- 'src/runtime/global_config.h'
- 'src/common/gpid.h'
- 'src/runtime/rpc/group_address.h'
- 'src/utils/logging_provider.h'
- 'src/runtime/rpc/message_parser.h'
- 'src/runtime/rpc/network.h'
- 'src/runtime/rpc/rpc_address.cpp'
Expand Down Expand Up @@ -617,8 +616,6 @@ header:
- 'src/utils/lockp.std.h'
- 'src/utils/logging.cpp'
- 'src/utils/shared_io_service.h'
- 'src/utils/simple_logger.cpp'
- 'src/utils/simple_logger.h'
- 'src/utils/strings.cpp'
- 'src/utils/test/CMakeLists.txt'
- 'src/utils/test/clear.sh'
Expand All @@ -637,7 +634,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'
Expand Down
6 changes: 6 additions & 0 deletions cmake_modules/BaseFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion src/aio/test/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/base/test/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/block_service/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/client/test/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/client_lib/pegasus_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

#include <fmt/core.h>
#include <pegasus/error.h>
#include <algorithm>
#include <chrono>
Expand Down
2 changes: 0 additions & 2 deletions src/common/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/failure_detector/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/failure_detector/test/config-whitelist-test-failed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/failure_detector/test/config-whitelist-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions src/geo/bench/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/geo/test/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/gutil/test/map_util_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <absl/hash/hash.h>
#include <absl/strings/string_view.h>
#include <fmt/core.h>
#include <stdint.h>
#include <algorithm>
#include <deque>
Expand Down
7 changes: 3 additions & 4 deletions src/http/pprof_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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"
Expand Down Expand Up @@ -98,7 +97,7 @@ static bool has_ext(const std::string &name, const std::string &ext)
static int extract_symbols_from_binary(std::map<uintptr_t, std::string> &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;
Expand Down Expand Up @@ -195,7 +194,7 @@ static int extract_symbols_from_binary(std::map<uintptr_t, std::string> &addr_ma

static void load_symbols()
{
SCOPED_LOG_TIMING(INFO, "load all symbols");
SCOPED_LOG_TIMING(info, "load all symbols");
auto fp = fopen("/proc/self/maps", "r");
if (fp == nullptr) {
return;
Expand Down Expand Up @@ -267,7 +266,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()) {
Expand Down
1 change: 0 additions & 1 deletion src/http/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/meta/duplication/meta_duplication_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "runtime/rpc/rpc_message.h"
#include "runtime/rpc/serialization.h"
#include "runtime/task/async_calls.h"
#include "utils/api_utilities.h"
#include "spdlog/common.h"
#include "utils/blob.h"
#include "utils/chrono_literals.h"
#include "utils/error_code.h"
Expand Down Expand Up @@ -174,10 +174,10 @@ void meta_duplication_service::do_modify_duplication(std::shared_ptr<app_state>
} 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.
Expand Down
1 change: 1 addition & 0 deletions src/meta/meta_state_service_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* THE SOFTWARE.
*/

#include <fmt/core.h>
#include <stddef.h>
#include <stdint.h>
#include <functional>
Expand Down
1 change: 1 addition & 0 deletions src/meta/test/backup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <set>
#include <string>
#include <thread>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down
2 changes: 0 additions & 2 deletions src/meta/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/meta/test/meta_state/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/nfs/nfs_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <utility>

#include "aio/file_io.h"
#include "fmt/core.h"
#include "nfs_code_definition.h"
#include "nfs_types.h"
#include "runtime/serverlet.h"
Expand Down
1 change: 0 additions & 1 deletion src/nfs/test/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/nfs/test/nfs_test_file1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/nfs/test/nfs_test_file2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/redis_protocol/proxy/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions src/redis_protocol/proxy_ut/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions src/replica/bulk_load/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/replica/replica_2pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
#include "runtime/task/task_code.h"
#include "runtime/task/task_spec.h"
#include "security/access_controller.h"
#include "spdlog/common.h"
#include "split/replica_split_manager.h"
#include "utils/api_utilities.h"
#include "utils/autoref_ptr.h"
#include "utils/error_code.h"
#include "utils/flags.h"
Expand Down Expand Up @@ -238,13 +238,13 @@ 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;
level = spdlog::level::info;
mu->set_timestamp(_uniq_timestamp_us.next());
} else {
mu->set_id(get_ballot(), mu->data.header.decree);
Expand Down
2 changes: 1 addition & 1 deletion src/replica/replica_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <unordered_map>
#include <utility>

#include "absl/strings/string_view.h"
#include "common/fs_manager.h"
#include "common/gpid.h"
#include "common/replication.codes.h"
Expand Down Expand Up @@ -58,7 +59,6 @@
#include "utils/fail_point.h"
#include "utils/flags.h"
#include "utils/fmt_logging.h"
#include "absl/strings/string_view.h"
#include "utils/metrics.h"
#include "utils/thread_access_checker.h"

Expand Down
2 changes: 1 addition & 1 deletion src/replica/replica_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "consensus_types.h"
#include "dsn.layer2_types.h"
#include "failure_detector/failure_detector_multimaster.h"
#include "gutil/map_util.h"
#include "meta_admin_types.h"
#include "metadata_types.h"
#include "mutation.h"
Expand All @@ -74,7 +75,6 @@
#include "utils/fail_point.h"
#include "utils/flags.h"
#include "utils/fmt_logging.h"
#include "gutil/map_util.h"
#include "utils/string_conv.h"
#include "utils/strings.h"
#include "utils/thread_access_checker.h"
Expand Down
2 changes: 0 additions & 2 deletions src/replica/split/test/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/replica/storage/simple_kv/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/replica/storage/simple_kv/test/case-000.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/replica/storage/simple_kv/test/case-001.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/replica/storage/simple_kv/test/case-002.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 25ef5db

Please sign in to comment.