Skip to content

Commit

Permalink
Re-namespace ::logger to ccf::logger
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Jun 28, 2024
1 parent 5bf09ce commit 2a34f3f
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions include/ccf/ds/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <sstream>
#include <type_traits>

namespace logger
namespace ccf::logger
{
static constexpr LoggerLevel MOST_VERBOSE =
#ifdef CCF_DISABLE_VERBOSE_LOGGING
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/apps/tpcc/clients/tpcc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down
6 changes: 3 additions & 3 deletions src/consensus/aft/test/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/consensus/aft/test/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#ifdef CCF_RAFT_TRACING
# define RAFT_DRIVER_PRINT(...) \
std::cout << "<RaftDriver> " << 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 << "<RaftDriver> " << fmt::format(__VA_ARGS__) << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/aft/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/ds/test/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class TestLogger : public Base
}
};

using TestTextLogger = TestLogger<logger::TextConsoleLogger>;
using TestJsonLogger = TestLogger<logger::JsonConsoleLogger>;
using TestTextLogger = TestLogger<ccf::logger::TextConsoleLogger>;
using TestJsonLogger = TestLogger<ccf::logger::JsonConsoleLogger>;

TEST_CASE("Framework logging macros")
{
std::vector<std::string> logs;

logger::config::loggers().emplace_back(
ccf::logger::config::loggers().emplace_back(
std::make_unique<TestTextLogger>(logs));

{
Expand Down Expand Up @@ -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<std::string> logs;

logger::config::loggers().emplace_back(
ccf::logger::config::loggers().emplace_back(
std::make_unique<TestTextLogger>(logs));

{
Expand Down Expand Up @@ -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";
Expand All @@ -135,7 +135,7 @@ TEST_CASE("Custom logging macros")
{
std::vector<std::string> logs;

logger::config::loggers().emplace_back(
ccf::logger::config::loggers().emplace_back(
std::make_unique<TestTextLogger>(logs));

{
Expand Down Expand Up @@ -177,5 +177,5 @@ TEST_CASE("Custom logging macros")
logs.clear();
}

logger::config::loggers().clear();
ccf::logger::config::loggers().clear();
}
20 changes: 10 additions & 10 deletions src/ds/test/logger_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ enum LoggerKind
template <LoggerKind LK, bool Absorb = true>
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<logger::TextConsoleLogger>());
ccf::logger::config::loggers().emplace_back(
std::make_unique<ccf::logger::TextConsoleLogger>());
}

if constexpr ((LK & LoggerKind::JSON) != 0)
{
logger::config::loggers().emplace_back(
std::make_unique<logger::JsonConsoleLogger>());
ccf::logger::config::loggers().emplace_back(
std::make_unique<ccf::logger::JsonConsoleLogger>());
}

if constexpr (Absorb)
Expand All @@ -41,7 +41,7 @@ static void prepare_loggers()

static void reset_loggers()
{
logger::config::loggers().clear();
ccf::logger::config::loggers().clear();

std::cout.clear();
}
Expand All @@ -51,7 +51,7 @@ static void log_accepted(picobench::state& s)
{
prepare_loggers<LK, Absorb>();

logger::config::level() = LoggerLevel::DEBUG;
ccf::logger::config::level() = LoggerLevel::DEBUG;
{
picobench::scope scope(s);

Expand All @@ -69,7 +69,7 @@ static void log_accepted_fmt(picobench::state& s)
{
prepare_loggers<LK, Absorb>();

logger::config::level() = LoggerLevel::DEBUG;
ccf::logger::config::level() = LoggerLevel::DEBUG;
{
picobench::scope scope(s);

Expand All @@ -87,7 +87,7 @@ static void log_rejected(picobench::state& s)
{
prepare_loggers<LK, Absorb>();

logger::config::level() = LoggerLevel::FAIL;
ccf::logger::config::level() = LoggerLevel::FAIL;
{
picobench::scope scope(s);

Expand All @@ -105,7 +105,7 @@ static void log_rejected_fmt(picobench::state& s)
{
prepare_loggers<LK, Absorb>();

logger::config::level() = LoggerLevel::FAIL;
ccf::logger::config::level() = LoggerLevel::FAIL;
{
picobench::scope scope(s);

Expand Down
4 changes: 2 additions & 2 deletions src/ds/test/logger_json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
12 changes: 6 additions & 6 deletions src/enclave/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extern "C"
auto new_logger = std::make_unique<ccf::RingbufferLogger>(
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();

Expand Down Expand Up @@ -234,20 +234,20 @@ 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)
{
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;

Expand Down
4 changes: 2 additions & 2 deletions src/enclave/ringbuffer_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ccf
{
class RingbufferLogger : public logger::AbstractLogger
class RingbufferLogger : public ccf::logger::AbstractLogger
{
protected:
ringbuffer::WriterPtr writer;
Expand All @@ -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<double>& enclave_offset = std::nullopt) override
{
writer->write(
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/test/endpoint_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::optional<PathTemplateSpec> require_parsed_components(

TEST_CASE("URL template parsing")
{
logger::config::default_init();
ccf::logger::config::default_init();

std::optional<PathTemplateSpec> parsed;
std::string path;
Expand Down
4 changes: 2 additions & 2 deletions src/host/handle_ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace asynchost
thread_id,
msg] = ringbuffer::read_message<AdminMessage::log_msg>(data, size);

logger::LogLine ll(
ccf::logger::LogLine ll(
log_level, tag, file_name.c_str(), line_number, thread_id);
ll.msg = msg;

Expand All @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/host/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ int main(int argc, char** argv)

LoggerLevel enclave_log_level = LoggerLevel::INFO;
std::map<std::string, LoggerLevel> 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/host/test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/http/test/http_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading

0 comments on commit 2a34f3f

Please sign in to comment.