Skip to content

Commit 0b34121

Browse files
committed
feat(logging): Introduce spdlog and remove simple_logger and screen_logger
1 parent 097068d commit 0b34121

21 files changed

Lines changed: 290 additions & 1023 deletions

.licenserc.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ header:
165165
- 'src/runtime/global_config.h'
166166
- 'src/common/gpid.h'
167167
- 'src/runtime/rpc/group_address.h'
168-
- 'src/utils/logging_provider.h'
169168
- 'src/runtime/rpc/message_parser.h'
170169
- 'src/runtime/rpc/network.h'
171170
- 'src/runtime/rpc/rpc_address.cpp'
@@ -617,8 +616,6 @@ header:
617616
- 'src/utils/lockp.std.h'
618617
- 'src/utils/logging.cpp'
619618
- 'src/utils/shared_io_service.h'
620-
- 'src/utils/simple_logger.cpp'
621-
- 'src/utils/simple_logger.h'
622619
- 'src/utils/strings.cpp'
623620
- 'src/utils/test/CMakeLists.txt'
624621
- 'src/utils/test/clear.sh'
@@ -637,7 +634,6 @@ header:
637634
- 'src/utils/test/join_point_test.cpp'
638635
- 'src/utils/test/json_helper_test.cpp'
639636
- 'src/utils/test/lock.std.cpp'
640-
- 'src/utils/test/logger.cpp'
641637
- 'src/utils/test/logging.cpp'
642638
- 'src/utils/test/output_utils_test.cpp'
643639
- 'src/utils/test/priority_queue.cpp'

cmake_modules/BaseFunctions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ function(dsn_setup_compiler_flags)
208208
if(${BUILD_TEST})
209209
add_definitions(-DMOCK_TEST)
210210
endif()
211+
add_definitions(-DSPDLOG_FMT_EXTERNAL)
212+
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG)
211213

212214
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -gdwarf-4" CACHE STRING "" FORCE)
213215

src/http/pprof_http_service.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static bool has_ext(const std::string &name, const std::string &ext)
9898
static int extract_symbols_from_binary(std::map<uintptr_t, std::string> &addr_map,
9999
const lib_info &lib_info)
100100
{
101-
SCOPED_LOG_TIMING(INFO, "load {}", lib_info.path);
101+
SCOPED_LOG_TIMING(info, "load {}", lib_info.path);
102102
std::string cmd = "nm -C -p ";
103103
cmd.append(lib_info.path);
104104
std::stringstream ss;
@@ -195,7 +195,7 @@ static int extract_symbols_from_binary(std::map<uintptr_t, std::string> &addr_ma
195195

196196
static void load_symbols()
197197
{
198-
SCOPED_LOG_TIMING(INFO, "load all symbols");
198+
SCOPED_LOG_TIMING(info, "load all symbols");
199199
auto fp = fopen("/proc/self/maps", "r");
200200
if (fp == nullptr) {
201201
return;
@@ -267,7 +267,7 @@ static void load_symbols()
267267
extract_symbols_from_binary(symbol_map, info);
268268

269269
size_t num_removed = 0;
270-
LOG_TIMING_IF(INFO, num_removed > 0, "removed {} entries", num_removed);
270+
LOG_TIMING_IF(info, num_removed > 0, "removed {} entries", num_removed);
271271
bool last_is_empty = false;
272272
for (auto it = symbol_map.begin(); it != symbol_map.end();) {
273273
if (it->second.empty()) {

src/meta/duplication/meta_duplication_service.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "utils/ports.h"
5656
#include "utils/string_conv.h"
5757
#include "utils/zlocks.h"
58+
#include "spdlog/common.h"
5859

5960
DSN_DECLARE_bool(dup_ignore_other_cluster_ids);
6061

@@ -174,10 +175,10 @@ void meta_duplication_service::do_modify_duplication(std::shared_ptr<app_state>
174175
} while (0)
175176

176177
#define LOG_WARNING_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, ...) \
177-
LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, LOG_LEVEL_WARNING, __VA_ARGS__)
178+
LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, spdlog::level::warn, __VA_ARGS__)
178179

179180
#define LOG_ERROR_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, ...) \
180-
LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, LOG_LEVEL_ERROR, __VA_ARGS__)
181+
LOG_DUP_HINT_AND_RETURN_IF_NOT(expr, resp, ec, spdlog::level::err, __VA_ARGS__)
181182

182183
// This call will not recreate if the duplication
183184
// with the same app name and remote end point already exists.

src/replica/replica_2pc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "utils/ports.h"
7878
#include "utils/thread_access_checker.h"
7979
#include "utils/uniq_timestamp_us.h"
80+
#include "spdlog/common.h"
8081

8182
DSN_DEFINE_bool(replication,
8283
reject_write_when_disk_insufficient,
@@ -238,13 +239,13 @@ void replica::init_prepare(mutation_ptr &mu, bool reconciliation, bool pop_all_c
238239
const auto request_count = mu->client_requests.size();
239240
mu->data.header.last_committed_decree = last_committed_decree();
240241

241-
log_level_t level = LOG_LEVEL_DEBUG;
242+
spdlog::level::level_enum level = spdlog::level::debug;
242243
if (mu->data.header.decree == invalid_decree) {
243244
mu->set_id(get_ballot(), _prepare_list->max_decree() + 1);
244245
// print a debug log if necessary
245246
if (FLAGS_prepare_decree_gap_for_debug_logging > 0 &&
246247
mu->get_decree() % FLAGS_prepare_decree_gap_for_debug_logging == 0)
247-
level = LOG_LEVEL_INFO;
248+
level = spdlog::level::info;
248249
mu->set_timestamp(_uniq_timestamp_us.next());
249250
} else {
250251
mu->set_id(get_ballot(), mu->data.header.decree);

src/runtime/rpc/rpc_host_port.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ host_port host_port::from_address(rpc_address addr)
5555
{
5656
host_port hp;
5757
SCOPED_LOG_SLOW_EXECUTION(
58-
WARNING, 100, "construct host_port '{}' from rpc_address '{}'", hp, addr);
58+
warn, 100, "construct host_port '{}' from rpc_address '{}'", hp, addr);
5959
switch (addr.type()) {
6060
case HOST_TYPE_IPV4: {
6161
const auto s = lookup_hostname(htonl(addr.ip()), &hp._host);
@@ -81,7 +81,7 @@ host_port host_port::from_string(const std::string &host_port_str)
8181
{
8282
host_port hp;
8383
SCOPED_LOG_SLOW_EXECUTION(
84-
WARNING, 100, "construct host_port '{}' from string '{}'", hp, host_port_str);
84+
warn, 100, "construct host_port '{}' from string '{}'", hp, host_port_str);
8585
const auto pos = host_port_str.find_last_of(':');
8686
if (dsn_unlikely(pos == std::string::npos)) {
8787
return hp;

src/runtime/service_api_c.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
#include "utils/flags.h"
7676
#include "utils/fmt_logging.h"
7777
#include "utils/join_point.h"
78-
#include "utils/logging_provider.h"
7978
#include "utils/process_utils.h"
8079
#include "utils/string_conv.h"
8180
#include "utils/strings.h"
8281
#include "utils/sys_exit_hook.h"
8382
#include "utils/threadpool_spec.h"
83+
#include "utils/logging.h"
8484

8585
DSN_DEFINE_bool(
8686
core,
@@ -343,33 +343,6 @@ inline void dsn_global_init()
343343
dsn::service_engine::instance();
344344
}
345345

346-
static std::string dsn_log_prefixed_message_func()
347-
{
348-
const int tid = dsn::utils::get_current_tid();
349-
const auto t = dsn::task::get_current_task_id();
350-
if (t) {
351-
if (nullptr != dsn::task::get_current_worker2()) {
352-
return fmt::format("{}.{}{}.{:016}: ",
353-
dsn::task::get_current_node_name(),
354-
dsn::task::get_current_worker2()->pool_spec().name,
355-
dsn::task::get_current_worker2()->index(),
356-
t);
357-
} else {
358-
return fmt::format(
359-
"{}.io-thrd.{}.{:016}: ", dsn::task::get_current_node_name(), tid, t);
360-
}
361-
} else {
362-
if (nullptr != dsn::task::get_current_worker2()) {
363-
return fmt::format("{}.{}{}: ",
364-
dsn::task::get_current_node_name(),
365-
dsn::task::get_current_worker2()->pool_spec().name,
366-
dsn::task::get_current_worker2()->index());
367-
} else {
368-
return fmt::format("{}.io-thrd.{}: ", dsn::task::get_current_node_name(), tid);
369-
}
370-
}
371-
}
372-
373346
bool run(const char *config_file,
374347
const char *config_arguments,
375348
bool is_server,
@@ -473,10 +446,7 @@ bool run(const char *config_file,
473446
}
474447
475448
// Initialize logging.
476-
dsn_log_init(spec.logging_factory_name,
477-
spec.log_dir,
478-
fmt::format("{}", fmt::join(app_names, ".")),
479-
dsn_log_prefixed_message_func);
449+
dsn_log_init(spec.log_dir, fmt::format("{}", fmt::join(app_names, ".")));
480450
481451
// Prepare the minimum necessary.
482452
::dsn::service_engine::instance().init_before_toollets(spec);

src/runtime/tool_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Component providers define the interface for the local components (e.g., network
5252
// providers
5353
#include "utils/factory_store.h"
5454
#include "utils/join_point.h"
55-
#include "utils/logging_provider.h" // IWYU pragma: keep
5655

5756
namespace dsn {
5857
class service_node;

src/security/sasl_init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,26 @@
2727
#include "utils/flags.h"
2828
#include "utils/fmt_logging.h"
2929
#include "utils/synchronize.h"
30+
#include "spdlog/common.h"
31+
#include "spdlog/spdlog.h"
3032

3133
DSN_DEFINE_string(security, sasl_plugin_path, "/usr/lib/sasl2", "path to search sasl plugins");
3234

3335
namespace dsn {
3436
namespace security {
3537

36-
log_level_t get_log_level(int level)
38+
spdlog::level::level_enum get_log_level(int level)
3739
{
3840
switch (level) {
3941
case SASL_LOG_ERR:
40-
return LOG_LEVEL_ERROR;
42+
return spdlog::level::err;
4143
case SASL_LOG_FAIL:
4244
case SASL_LOG_WARN:
43-
return LOG_LEVEL_WARNING;
45+
return spdlog::level::warn;
4446
case SASL_LOG_NOTE:
45-
return LOG_LEVEL_INFO;
47+
return spdlog::level::info;
4648
default:
47-
return LOG_LEVEL_DEBUG;
49+
return spdlog::level::debug;
4850
}
4951
}
5052

src/utils/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ set(MY_PROJ_LIBS
3737
lz4
3838
zstd
3939
snappy
40-
absl::strings)
40+
absl::strings
41+
spdlog)
4142

4243
# Extra files that will be installed
4344
set(MY_BINPLACES "")

0 commit comments

Comments
 (0)