From 2a34f3fe63941650e193621a9ab5ffed1d585b9d Mon Sep 17 00:00:00 2001 From: Amaury Chamayou Date: Fri, 28 Jun 2024 09:37:21 +0000 Subject: [PATCH] Re-namespace ::logger to ccf::logger --- CHANGELOG.md | 1 + include/ccf/ds/logger.h | 10 +++++----- src/apps/tpcc/clients/tpcc_client.cpp | 4 ++-- src/consensus/aft/test/driver.cpp | 6 +++--- src/consensus/aft/test/driver.h | 3 ++- src/consensus/aft/test/main.cpp | 2 +- src/ds/test/logger.cpp | 16 ++++++++-------- src/ds/test/logger_bench.cpp | 20 ++++++++++---------- src/ds/test/logger_json_test.cpp | 4 ++-- src/enclave/main.cpp | 12 ++++++------ src/enclave/ringbuffer_logger.h | 4 ++-- src/endpoints/test/endpoint_registry.cpp | 2 +- src/host/handle_ring_buffer.h | 4 ++-- src/host/main.cpp | 11 ++++++----- src/host/test/ledger.cpp | 2 +- src/http/test/http_test.cpp | 2 +- src/kv/test/kv_bench.cpp | 10 +++++----- src/kv/test/kv_contention.cpp | 2 +- src/kv/test/kv_test.cpp | 2 +- src/node/test/encryptor.cpp | 2 +- src/node/test/endorsements.cpp | 2 +- src/node/test/history_bench.cpp | 2 +- src/node/test/snapshotter.cpp | 4 ++-- tests/perf-system/submitter/submit.cpp | 4 ++-- 24 files changed, 67 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85723c70499d..3680401253f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `::tls` is now `ccf::tls` - `::nonstd` is now `ccf::nonstd` - `::crypto` is now `ccf::crypto` + - `::logger` is now `ccf::logger` - The `programmability` sample app now demonstrates how applications can define their own extensions, creating bindings between C++ and JS state, and allowing JS endpoints to call functions implemented in C++. - Introduce `DynamicJSEndpointRegistry::record_action_for_audit_v1` and `DynamicJSEndpointRegistry::check_action_not_replayed_v1` to allow an application making use of the programmability feature to easily implement auditability, and protect users allowed to update the application against replay attacks (#6285). - Endpoints now support a `ToBackup` redirection strategy, for requests which should never be executed on a primary. These must also be read-only. These are configured similar to `ToPrimary` endpoints, with a `to_backup` object (specifying by-role or statically-addressed targets) in each node's configuration. diff --git a/include/ccf/ds/logger.h b/include/ccf/ds/logger.h index 003bd4f9ef46..9d677820d960 100644 --- a/include/ccf/ds/logger.h +++ b/include/ccf/ds/logger.h @@ -15,7 +15,7 @@ #include #include -namespace logger +namespace ccf::logger { static constexpr LoggerLevel MOST_VERBOSE = #ifdef CCF_DISABLE_VERBOSE_LOGGING @@ -356,9 +356,9 @@ namespace logger // This allows: // CCF_LOG_OUT(DEBUG, "foo") << "this " << "msg"; #define CCF_LOG_OUT(LVL, TAG) \ - logger::config::ok(LoggerLevel::LVL) && \ - logger::Out() == \ - logger::LogLine(LoggerLevel::LVL, TAG, __FILE__, __LINE__) + ccf::logger::config::ok(LoggerLevel::LVL) && \ + ccf::logger::Out() == \ + ccf::logger::LogLine(LoggerLevel::LVL, TAG, __FILE__, __LINE__) // To avoid repeating the (s, ...) args for every macro, we cheat with a curried // macro here by ending the macro with another macro name, which then accepts @@ -376,7 +376,7 @@ namespace logger }; #ifndef CCF_LOGGER_NO_DEPRECATE -# define CCF_LOGGER_DEPRECATE(MACRO) logger::macro::MACRO; +# define CCF_LOGGER_DEPRECATE(MACRO) ccf::logger::macro::MACRO; #else # define CCF_LOGGER_DEPRECATE(MACRO) #endif diff --git a/src/apps/tpcc/clients/tpcc_client.cpp b/src/apps/tpcc/clients/tpcc_client.cpp index 0ccd693fc6f4..3bc17e16997c 100644 --- a/src/apps/tpcc/clients/tpcc_client.cpp +++ b/src/apps/tpcc/clients/tpcc_client.cpp @@ -155,8 +155,8 @@ class TpccClient : public Base int main(int argc, char** argv) { - logger::config::default_init(); - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::default_init(); + ccf::logger::config::level() = LoggerLevel::INFO; ccf::crypto::openssl_sha256_init(); CLI::App cli_app{"Tpcc Client"}; diff --git a/src/consensus/aft/test/driver.cpp b/src/consensus/aft/test/driver.cpp index 8064e412384c..c85802a43501 100644 --- a/src/consensus/aft/test/driver.cpp +++ b/src/consensus/aft/test/driver.cpp @@ -40,11 +40,11 @@ int main(int argc, char** argv) // Log all raft steps to stdout (python wrapper raft_scenario_runner.py // filters them). #ifdef CCF_RAFT_TRACING - logger::config::add_json_console_logger(); + ccf::logger::config::add_json_console_logger(); #else - logger::config::add_text_console_logger(); + ccf::logger::config::add_text_console_logger(); #endif - logger::config::level() = LoggerLevel::DEBUG; + ccf::logger::config::level() = LoggerLevel::DEBUG; threading::ThreadMessaging::init(1); diff --git a/src/consensus/aft/test/driver.h b/src/consensus/aft/test/driver.h index 486d6f180427..eeb8e07603d4 100644 --- a/src/consensus/aft/test/driver.h +++ b/src/consensus/aft/test/driver.h @@ -17,7 +17,8 @@ #ifdef CCF_RAFT_TRACING # define RAFT_DRIVER_PRINT(...) \ std::cout << " " << fmt::format(__VA_ARGS__) \ - << fmt::format(" (ts={})", logger::logical_clock) << std::endl; + << fmt::format(" (ts={})", ccf::logger::logical_clock) \ + << std::endl; #else # define RAFT_DRIVER_PRINT(...) \ std::cout << " " << fmt::format(__VA_ARGS__) << std::endl; diff --git a/src/consensus/aft/test/main.cpp b/src/consensus/aft/test/main.cpp index c5e35233cc72..6ff7d98d483f 100644 --- a/src/consensus/aft/test/main.cpp +++ b/src/consensus/aft/test/main.cpp @@ -769,7 +769,7 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple")) DOCTEST_TEST_CASE("Exceed append entries limit") { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; ccf::NodeId node_id0 = kv::test::PrimaryNodeId; ccf::NodeId node_id1 = kv::test::FirstBackupNodeId; diff --git a/src/ds/test/logger.cpp b/src/ds/test/logger.cpp index bf6d79a44dd4..35eec285a981 100644 --- a/src/ds/test/logger.cpp +++ b/src/ds/test/logger.cpp @@ -20,14 +20,14 @@ class TestLogger : public Base } }; -using TestTextLogger = TestLogger; -using TestJsonLogger = TestLogger; +using TestTextLogger = TestLogger; +using TestJsonLogger = TestLogger; TEST_CASE("Framework logging macros") { std::vector logs; - logger::config::loggers().emplace_back( + ccf::logger::config::loggers().emplace_back( std::make_unique(logs)); { @@ -69,14 +69,14 @@ TEST_CASE("Framework logging macros") logs.clear(); } - logger::config::loggers().clear(); + ccf::logger::config::loggers().clear(); } TEST_CASE("Application logging macros") { std::vector logs; - logger::config::loggers().emplace_back( + ccf::logger::config::loggers().emplace_back( std::make_unique(logs)); { @@ -121,7 +121,7 @@ TEST_CASE("Application logging macros") logs.clear(); } - logger::config::loggers().clear(); + ccf::logger::config::loggers().clear(); } constexpr auto custom_tag = "my tag"; @@ -135,7 +135,7 @@ TEST_CASE("Custom logging macros") { std::vector logs; - logger::config::loggers().emplace_back( + ccf::logger::config::loggers().emplace_back( std::make_unique(logs)); { @@ -177,5 +177,5 @@ TEST_CASE("Custom logging macros") logs.clear(); } - logger::config::loggers().clear(); + ccf::logger::config::loggers().clear(); } \ No newline at end of file diff --git a/src/ds/test/logger_bench.cpp b/src/ds/test/logger_bench.cpp index 6e54b15bdde5..8eff56c00306 100644 --- a/src/ds/test/logger_bench.cpp +++ b/src/ds/test/logger_bench.cpp @@ -18,18 +18,18 @@ enum LoggerKind template static void prepare_loggers() { - logger::config::loggers().clear(); + ccf::logger::config::loggers().clear(); if constexpr ((LK & LoggerKind::Console) != 0) { - logger::config::loggers().emplace_back( - std::make_unique()); + ccf::logger::config::loggers().emplace_back( + std::make_unique()); } if constexpr ((LK & LoggerKind::JSON) != 0) { - logger::config::loggers().emplace_back( - std::make_unique()); + ccf::logger::config::loggers().emplace_back( + std::make_unique()); } if constexpr (Absorb) @@ -41,7 +41,7 @@ static void prepare_loggers() static void reset_loggers() { - logger::config::loggers().clear(); + ccf::logger::config::loggers().clear(); std::cout.clear(); } @@ -51,7 +51,7 @@ static void log_accepted(picobench::state& s) { prepare_loggers(); - logger::config::level() = LoggerLevel::DEBUG; + ccf::logger::config::level() = LoggerLevel::DEBUG; { picobench::scope scope(s); @@ -69,7 +69,7 @@ static void log_accepted_fmt(picobench::state& s) { prepare_loggers(); - logger::config::level() = LoggerLevel::DEBUG; + ccf::logger::config::level() = LoggerLevel::DEBUG; { picobench::scope scope(s); @@ -87,7 +87,7 @@ static void log_rejected(picobench::state& s) { prepare_loggers(); - logger::config::level() = LoggerLevel::FAIL; + ccf::logger::config::level() = LoggerLevel::FAIL; { picobench::scope scope(s); @@ -105,7 +105,7 @@ static void log_rejected_fmt(picobench::state& s) { prepare_loggers(); - logger::config::level() = LoggerLevel::FAIL; + ccf::logger::config::level() = LoggerLevel::FAIL; { picobench::scope scope(s); diff --git a/src/ds/test/logger_json_test.cpp b/src/ds/test/logger_json_test.cpp index 3d6e2b8daef4..4f75114fa35f 100644 --- a/src/ds/test/logger_json_test.cpp +++ b/src/ds/test/logger_json_test.cpp @@ -13,8 +13,8 @@ TEST_CASE("Test custom log format") { std::string test_log_file = "./test_json_logger.txt"; remove(test_log_file.c_str()); - logger::config::add_json_console_logger(); - logger::config::level() = LoggerLevel::DEBUG; + ccf::logger::config::add_json_console_logger(); + ccf::logger::config::level() = LoggerLevel::DEBUG; std::string log_msg_dbg = "log_msg_dbg"; std::string log_msg_trace = "log_msg_trace"; diff --git a/src/enclave/main.cpp b/src/enclave/main.cpp index 67abd7493613..04944823b967 100644 --- a/src/enclave/main.cpp +++ b/src/enclave/main.cpp @@ -132,7 +132,7 @@ extern "C" auto new_logger = std::make_unique( writer_factory->create_writer_to_outside()); auto ringbuffer_logger = new_logger.get(); - logger::config::loggers().push_back(std::move(new_logger)); + ccf::logger::config::loggers().push_back(std::move(new_logger)); ccf::pal::redirect_platform_logging(); @@ -234,7 +234,7 @@ extern "C" // minimum logging level (maximum verbosity) restricted at compile-time, // while other platforms can permit any level at compile-time and then bind // the run-time choice in attestations. - const auto mv = logger::MOST_VERBOSE; + const auto mv = ccf::logger::MOST_VERBOSE; const auto requested = enclave_log_level; const auto permitted = std::max(mv, requested); if (requested != permitted) @@ -242,12 +242,12 @@ extern "C" LOG_FAIL_FMT( "Unable to set requested enclave logging level '{}'. Most verbose " "permitted level is '{}', so setting level to '{}'.", - logger::to_string(requested), - logger::to_string(mv), - logger::to_string(permitted)); + ccf::logger::to_string(requested), + ccf::logger::to_string(mv), + ccf::logger::to_string(permitted)); } - logger::config::level() = permitted; + ccf::logger::config::level() = permitted; ccf::Enclave* enclave = nullptr; diff --git a/src/enclave/ringbuffer_logger.h b/src/enclave/ringbuffer_logger.h index db5c169a8b63..c39f0777db76 100644 --- a/src/enclave/ringbuffer_logger.h +++ b/src/enclave/ringbuffer_logger.h @@ -6,7 +6,7 @@ namespace ccf { - class RingbufferLogger : public logger::AbstractLogger + class RingbufferLogger : public ccf::logger::AbstractLogger { protected: ringbuffer::WriterPtr writer; @@ -19,7 +19,7 @@ namespace ccf RingbufferLogger(const ringbuffer::WriterPtr& writer_) : writer(writer_) {} void write( - const logger::LogLine& line, + const ccf::logger::LogLine& line, const std::optional& enclave_offset = std::nullopt) override { writer->write( diff --git a/src/endpoints/test/endpoint_registry.cpp b/src/endpoints/test/endpoint_registry.cpp index 59e544aeb7ce..9a2d26495569 100644 --- a/src/endpoints/test/endpoint_registry.cpp +++ b/src/endpoints/test/endpoint_registry.cpp @@ -29,7 +29,7 @@ std::optional require_parsed_components( TEST_CASE("URL template parsing") { - logger::config::default_init(); + ccf::logger::config::default_init(); std::optional parsed; std::string path; diff --git a/src/host/handle_ring_buffer.h b/src/host/handle_ring_buffer.h index ea3d14ed0ae0..311d13552ad6 100644 --- a/src/host/handle_ring_buffer.h +++ b/src/host/handle_ring_buffer.h @@ -49,7 +49,7 @@ namespace asynchost thread_id, msg] = ringbuffer::read_message(data, size); - logger::LogLine ll( + ccf::logger::LogLine ll( log_level, tag, file_name.c_str(), line_number, thread_id); ll.msg = msg; @@ -76,7 +76,7 @@ namespace asynchost offset_time = enclave_time_s - host_time_s; } - auto& loggers = logger::config::loggers(); + auto& loggers = ccf::logger::config::loggers(); for (auto const& logger : loggers) { logger->write(ll, offset_time); diff --git a/src/host/main.cpp b/src/host/main.cpp index 98e445910397..b3c13e018a1b 100644 --- a/src/host/main.cpp +++ b/src/host/main.cpp @@ -106,10 +106,11 @@ int main(int argc, char** argv) LoggerLevel enclave_log_level = LoggerLevel::INFO; std::map log_level_options; - for (size_t i = logger::MOST_VERBOSE; i < LoggerLevel::MAX_LOG_LEVEL; ++i) + for (size_t i = ccf::logger::MOST_VERBOSE; i < LoggerLevel::MAX_LOG_LEVEL; + ++i) { const auto l = (LoggerLevel)i; - log_level_options[logger::to_string(l)] = l; + log_level_options[ccf::logger::to_string(l)] = l; } app @@ -179,11 +180,11 @@ int main(int argc, char** argv) if (config.logging.format == host::LogFormat::JSON) { - logger::config::add_json_console_logger(); + ccf::logger::config::add_json_console_logger(); } else { - logger::config::add_text_console_logger(); + ccf::logger::config::add_text_console_logger(); } LOG_INFO_FMT("CCF version: {}", ccf::ccf_version); @@ -271,7 +272,7 @@ int main(int argc, char** argv) files::dump(fmt::format("{}", ::getpid()), config.output_files.pid_file); // set the host log level - logger::config::level() = config.logging.host_level; + ccf::logger::config::level() = config.logging.host_level; asynchost::TimeBoundLogger::default_max_time = config.slow_io_logging_threshold; diff --git a/src/host/test/ledger.cpp b/src/host/test/ledger.cpp index 9550ece99e3e..1da62c2801b6 100644 --- a/src/host/test/ledger.cpp +++ b/src/host/test/ledger.cpp @@ -1726,7 +1726,7 @@ TEST_CASE("Ledger init with existing files") int main(int argc, char** argv) { - logger::config::default_init(); + ccf::logger::config::default_init(); ccf::crypto::openssl_sha256_init(); doctest::Context context; context.applyCommandLine(argc, argv); diff --git a/src/http/test/http_test.cpp b/src/http/test/http_test.cpp index e08dc1bf4c32..953c91588aca 100644 --- a/src/http/test/http_test.cpp +++ b/src/http/test/http_test.cpp @@ -277,7 +277,7 @@ DOCTEST_TEST_CASE("URL parsing") DOCTEST_TEST_CASE("Pessimal transport") { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; const http::HeaderMap h1 = {{"foo", "bar"}, {"baz", "42"}}; const http::HeaderMap h2 = { diff --git a/src/kv/test/kv_bench.cpp b/src/kv/test/kv_bench.cpp index 13c7f1645bb2..02094fe40178 100644 --- a/src/kv/test/kv_bench.cpp +++ b/src/kv/test/kv_bench.cpp @@ -53,7 +53,7 @@ std::string build_map_name(const std::string& core_name, kv::SecurityDomain sd) template static void serialise(picobench::state& s) { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; kv::Store kv_store; auto secrets = create_ledger_secrets(); @@ -85,7 +85,7 @@ static void serialise(picobench::state& s) template static void deserialise(picobench::state& s) { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; kv::Store kv_store; kv::Store kv_store2; @@ -126,7 +126,7 @@ static void deserialise(picobench::state& s) template static void commit_latency(picobench::state& s) { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; kv::Store kv_store; auto secrets = create_ledger_secrets(); @@ -164,7 +164,7 @@ static void commit_latency(picobench::state& s) template static void ser_snap(picobench::state& s) { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; kv::Store kv_store; auto secrets = create_ledger_secrets(); @@ -202,7 +202,7 @@ static void ser_snap(picobench::state& s) template static void des_snap(picobench::state& s) { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; kv::Store kv_store; kv::Store kv_store2; diff --git a/src/kv/test/kv_contention.cpp b/src/kv/test/kv_contention.cpp index 6f027d915cfb..2cd77c259bcb 100644 --- a/src/kv/test/kv_contention.cpp +++ b/src/kv/test/kv_contention.cpp @@ -36,7 +36,7 @@ class SlowStubConsensus : public kv::test::StubConsensus DOCTEST_TEST_CASE("Concurrent kv access" * doctest::test_suite("concurrency")) { - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::level() = LoggerLevel::INFO; // Multiple threads write random entries into random tables, and attempt to // commit them. A single thread continually compacts the kv to the latest diff --git a/src/kv/test/kv_test.cpp b/src/kv/test/kv_test.cpp index 1e38614b1066..9ea5e1c2e4a5 100644 --- a/src/kv/test/kv_test.cpp +++ b/src/kv/test/kv_test.cpp @@ -3309,7 +3309,7 @@ TEST_CASE("Ledger entry chunk request") int main(int argc, char** argv) { - logger::config::default_init(); + ccf::logger::config::default_init(); ccf::crypto::openssl_sha256_init(); doctest::Context context; context.applyCommandLine(argc, argv); diff --git a/src/node/test/encryptor.cpp b/src/node/test/encryptor.cpp index aae259efce31..89f4e3792f48 100644 --- a/src/node/test/encryptor.cpp +++ b/src/node/test/encryptor.cpp @@ -448,7 +448,7 @@ TEST_CASE("Encryptor rollback") int main(int argc, char** argv) { - logger::config::default_init(); + ccf::logger::config::default_init(); ccf::crypto::openssl_sha256_init(); doctest::Context context; context.applyCommandLine(argc, argv); diff --git a/src/node/test/endorsements.cpp b/src/node/test/endorsements.cpp index c0c791a5f8b9..743d615e4b96 100644 --- a/src/node/test/endorsements.cpp +++ b/src/node/test/endorsements.cpp @@ -67,7 +67,7 @@ TEST_CASE("Check ECDSA Test endorsement") int main(int argc, char** argv) { - logger::config::default_init(); + ccf::logger::config::default_init(); ccf::crypto::openssl_sha256_init(); doctest::Context context; context.applyCommandLine(argc, argv); diff --git a/src/node/test/history_bench.cpp b/src/node/test/history_bench.cpp index fec030bb88b0..1b6364acffc3 100644 --- a/src/node/test/history_bench.cpp +++ b/src/node/test/history_bench.cpp @@ -161,7 +161,7 @@ PICOBENCH(append_compact<1000>).iterations(sizes).samples(10); int main(int argc, char* argv[]) { - logger::config::level() = LoggerLevel::FATAL; + ccf::logger::config::level() = LoggerLevel::FATAL; ::threading::ThreadMessaging::init(1); ccf::crypto::openssl_sha256_init(); diff --git a/src/node/test/snapshotter.cpp b/src/node/test/snapshotter.cpp index eda0790eac87..681de0972122 100644 --- a/src/node/test/snapshotter.cpp +++ b/src/node/test/snapshotter.cpp @@ -135,7 +135,7 @@ void record_snapshot_evidence( TEST_CASE("Regular snapshotting") { - logger::config::default_init(); + ccf::logger::config::default_init(); ccf::NetworkState network; @@ -429,7 +429,7 @@ TEST_CASE("Rollback before snapshot is committed") // https://github.com/microsoft/CCF/issues/3796 TEST_CASE("Rekey ledger while snapshot is in progress") { - logger::config::default_init(); + ccf::logger::config::default_init(); ccf::NetworkState network; diff --git a/tests/perf-system/submitter/submit.cpp b/tests/perf-system/submitter/submit.cpp index ab05cd76dd21..1d73a5b60ced 100644 --- a/tests/perf-system/submitter/submit.cpp +++ b/tests/perf-system/submitter/submit.cpp @@ -265,8 +265,8 @@ int main(int argc, char** argv) // Ignore SIGPIPE as it can be raised by write to a socket signal(SIGPIPE, SIG_IGN); - logger::config::default_init(); - logger::config::level() = LoggerLevel::INFO; + ccf::logger::config::default_init(); + ccf::logger::config::level() = LoggerLevel::INFO; ccf::crypto::openssl_sha256_init(); CLI::App cli_app{"Perf Tool"}; ArgumentParser args("Perf Tool", cli_app);