Skip to content

Commit

Permalink
Remove legacy logger
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jan 9, 2024
1 parent 166077d commit addcd24
Show file tree
Hide file tree
Showing 46 changed files with 107 additions and 982 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,6 @@ include_directories(${BOOST_LIBRARY_INCLUDES})
add_library(Boost::stacktrace ALIAS boost_stacktrace_basic)
add_definitions(-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)

# Workaround for GitHub builders which do not appear to have the Windows Message
# Compiler mc.exe
add_definitions(-DBOOST_LOG_WITHOUT_EVENT_LOG)

# Workaround for missing reference errata in the boost property_tree module
target_link_libraries(boost_property_tree INTERFACE Boost::any)
target_link_libraries(boost_property_tree INTERFACE Boost::format)
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <nano/crypto_lib/random_pool.hpp>
#include <nano/lib/lmdbconfig.hpp>
#include <nano/lib/logger_mt.hpp>
#include <nano/lib/logging.hpp>
#include <nano/lib/stats.hpp>
#include <nano/lib/utility.hpp>
#include <nano/lib/work.hpp>
Expand Down
36 changes: 18 additions & 18 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ TEST (bulk_pull, count_limit)
TEST (bootstrap_processor, DISABLED_process_none)
{
nano::test::system system (1);
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node1->init_error ());
auto done (false);
node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint (), false);
Expand Down Expand Up @@ -338,7 +338,7 @@ TEST (bootstrap_processor, process_two)
ASSERT_NE (hash1, hash3);
ASSERT_NE (hash2, hash3);

auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node1->init_error ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
Expand Down Expand Up @@ -384,7 +384,7 @@ TEST (bootstrap_processor, process_state)
ASSERT_EQ (nano::process_result::progress, node0->process (*block2).code);

config.peering_port = system.get_available_port ();
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work, node_flags));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work, node_flags));
ASSERT_EQ (node0->latest (nano::dev::genesis_key.pub), block2->hash ());
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), block2->hash ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
Expand Down Expand Up @@ -415,7 +415,7 @@ TEST (bootstrap_processor, process_new)
nano::uint128_t balance2 (node1->balance (key2.pub));
ASSERT_TIMELY (10s, node1->block_confirmed (send->hash ()) && node1->block_confirmed (receive->hash ()) && node1->active.empty () && node2->active.empty ()); // All blocks should be propagated & confirmed

auto node3 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node3 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node3->init_error ());
node3->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY (10s, node3->balance (key2.pub) == balance2);
Expand Down Expand Up @@ -468,7 +468,7 @@ TEST (bootstrap_processor, pull_diamond)
.work (*system.work.generate (send1->hash ()))
.build_shared ();
ASSERT_EQ (nano::process_result::progress, node0->process (*receive).code);
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node1->init_error ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY (10s, node1->balance (nano::dev::genesis_key.pub) == 100);
Expand Down Expand Up @@ -529,7 +529,7 @@ TEST (bootstrap_processor, DISABLED_push_diamond)
config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto node0 (system.add_node (config));
nano::keypair key;
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node1->init_error ());
auto wallet1 (node1->wallets.create (100));
wallet1->insert_adhoc (nano::dev::genesis_key.prv);
Expand Down Expand Up @@ -662,7 +662,7 @@ TEST (bootstrap_processor, push_one)
config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto node0 (system.add_node (config));
nano::keypair key1;
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
ASSERT_NE (nullptr, wallet);
wallet->insert_adhoc (nano::dev::genesis_key.prv);
Expand Down Expand Up @@ -736,7 +736,7 @@ TEST (bootstrap_processor, lazy_hash)
node0->block_processor.add (receive2);
node0->block_processor.flush ();
// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (receive2->hash (), true);
{
Expand Down Expand Up @@ -810,7 +810,7 @@ TEST (bootstrap_processor, lazy_hash_bootstrap_id)
node0->block_processor.add (receive2);
node0->block_processor.flush ();
// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (receive2->hash (), true, "123456");
{
Expand Down Expand Up @@ -1052,7 +1052,7 @@ TEST (bootstrap_processor, lazy_max_pull_count)
node0->block_processor.add (change3);
node0->block_processor.flush ();
// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (change3->hash ());
// Check processed blocks
Expand Down Expand Up @@ -1390,7 +1390,7 @@ TEST (bootstrap_processor, lazy_cancel)
.build_shared ();

// Start lazy bootstrap with last block in chain known
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (send1->hash (), true); // Start "confirmed" block bootstrap
{
Expand Down Expand Up @@ -1465,7 +1465,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier)
node0->block_processor.add (receive2);
node0->block_processor.flush ();
// Start wallet lazy bootstrap
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
ASSERT_NE (nullptr, wallet);
Expand Down Expand Up @@ -1911,14 +1911,14 @@ TEST (frontier_req, confirmed_frontier)
TEST (bulk, genesis)
{
nano::test::system system;
nano::node_config config (system.get_available_port (), system.logging);
nano::node_config config (system.get_available_port ());
config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
nano::node_flags node_flags;
node_flags.disable_bootstrap_bulk_push_client = true;
node_flags.disable_lazy_bootstrap = true;
auto node1 = system.add_node (config, node_flags);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node2->init_error ());
nano::block_hash latest1 (node1->latest (nano::dev::genesis_key.pub));
nano::block_hash latest2 (node2->latest (nano::dev::genesis_key.pub));
Expand All @@ -1938,14 +1938,14 @@ TEST (bulk, genesis)
TEST (bulk, offline_send)
{
nano::test::system system;
nano::node_config config (system.get_available_port (), system.logging);
nano::node_config config (system.get_available_port ());
config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
nano::node_flags node_flags;
node_flags.disable_bootstrap_bulk_push_client = true;
node_flags.disable_lazy_bootstrap = true;
auto node1 = system.add_node (config, node_flags);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node2->init_error ());
node2->start ();
system.nodes.push_back (node2);
Expand Down Expand Up @@ -1980,7 +1980,7 @@ TEST (bulk, offline_send)
TEST (bulk, DISABLED_genesis_pruning)
{
nano::test::system system;
nano::node_config config (system.get_available_port (), system.logging);
nano::node_config config (system.get_available_port ());
config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
config.enable_voting = false; // Remove after allowing pruned voting
nano::node_flags node_flags;
Expand All @@ -1991,7 +1991,7 @@ TEST (bulk, DISABLED_genesis_pruning)
auto node1 = system.add_node (config, node_flags);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
node_flags.enable_pruning = false;
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work, node_flags));
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work, node_flags));
ASSERT_FALSE (node2->init_error ());
nano::block_hash latest1 (node1->latest (nano::dev::genesis_key.pub));
nano::block_hash latest2 (node2->latest (nano::dev::genesis_key.pub));
Expand Down
1 change: 0 additions & 1 deletion nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,6 @@ TEST (confirmation_height, unbounded_block_cache_iteration)
TEST (confirmation_height, pruned_source)
{
nano::nlogger logger;
nano::logging logging;
auto path (nano::unique_path ());
auto store = nano::make_store (logger, path, nano::dev::constants);
ASSERT_TRUE (!store->init_error ());
Expand Down
4 changes: 0 additions & 4 deletions nano/core_test/core_test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <nano/lib/logging.hpp>
#include <nano/node/common.hpp>
#include <nano/node/logging.hpp>
#include <nano/secure/utility.hpp>

#include <boost/filesystem/path.hpp>
Expand All @@ -24,9 +23,6 @@ GTEST_API_ int main (int argc, char ** argv)
nano::set_file_descriptor_limit (OPEN_FILE_DESCRIPTORS_LIMIT);
nano::force_nano_dev_network ();
nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;
// Setting up logging so that there aren't any piped to standard output.
nano::logging logging;
logging.init (nano::unique_path ());
testing::InitGoogleTest (&argc, argv);
auto res = RUN_ALL_TESTS ();
nano::test::cleanup_dev_directories_on_exit ();
Expand Down
98 changes: 3 additions & 95 deletions nano/core_test/logger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <nano/lib/logger_mt.hpp>
#include <nano/node/logging.hpp>

#include <nano/secure/utility.hpp>
#include <nano/test_common/testutil.hpp>

Expand All @@ -13,98 +12,7 @@

using namespace std::chrono_literals;

TEST (logger, changing_time_interval)
{
auto path1 (nano::unique_path ());
nano::logging logging;
logging.init (path1);
logging.min_time_between_log_output = 0ms;
nano::logger_mt my_logger (logging.min_time_between_log_output);
auto error (my_logger.try_log ("logger.changing_time_interval1"));
ASSERT_FALSE (error);
my_logger.min_log_delta = 20s;
error = my_logger.try_log ("logger, changing_time_interval2");
ASSERT_TRUE (error);
}

TEST (logger, try_log)
TEST (logger, basic)
{
auto path1 (nano::unique_path ());
std::stringstream ss;
nano::test::boost_log_cerr_redirect redirect_cerr (ss.rdbuf ());
nano::logger_mt my_logger (100ms);
auto output1 = "logger.try_log1";
auto error (my_logger.try_log (output1));
ASSERT_FALSE (error);
auto output2 = "logger.try_log2";
error = my_logger.try_log (output2);
ASSERT_TRUE (error); // Fails as it is occuring too soon

// Sleep for a bit and then confirm
std::this_thread::sleep_for (100ms);
error = my_logger.try_log (output2);
ASSERT_FALSE (error);

std::string str;
std::getline (ss, str, '\n');
ASSERT_STREQ (str.c_str (), output1);
std::getline (ss, str, '\n');
ASSERT_STREQ (str.c_str (), output2);
}

TEST (logger, always_log)
{
auto path1 (nano::unique_path ());
std::stringstream ss;
nano::test::boost_log_cerr_redirect redirect_cerr (ss.rdbuf ());
nano::logger_mt my_logger (20s); // Make time interval effectively unreachable
auto output1 = "logger.always_log1";
auto error (my_logger.try_log (output1));
ASSERT_FALSE (error);

// Time is too soon after, so it won't be logged
auto output2 = "logger.always_log2";
error = my_logger.try_log (output2);
ASSERT_TRUE (error);

// Force it to be logged
my_logger.always_log (output2);

std::string str;
std::getline (ss, str, '\n');
ASSERT_STREQ (str.c_str (), output1);
std::getline (ss, str, '\n');
ASSERT_STREQ (str.c_str (), output2);
}

TEST (logger, stable_filename)
{
auto path (nano::unique_path ());
nano::logging logging;

// Releasing allows setting up logging again
logging.release_file_sink ();

logging.stable_log_filename = true;
logging.init (path);

nano::logger_mt logger (logging.min_time_between_log_output);
logger.always_log ("stable1");

auto log_file = path / "log" / "node.log";

#if BOOST_VERSION >= 107000
EXPECT_TRUE (std::filesystem::exists (log_file));
// Try opening it again
logging.release_file_sink ();
logging.init (path);
logger.always_log ("stable2");
#else
// When using Boost < 1.70 , behavior is reverted to not using the stable filename
EXPECT_FALSE (std::filesystem::exists (log_file));
#endif

// Reset the logger
logging.release_file_sink ();
nano::logging ().init (path);
// TODO
}
16 changes: 8 additions & 8 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST (network, construction_with_specified_port)
{
nano::test::system system{};
auto const port = system.get_available_port (/* do not allow 0 port */ false);
auto const node = system.add_node (nano::node_config{ port, system.logging });
auto const node = system.add_node (nano::node_config{ port });
EXPECT_EQ (port, node->network.port);
EXPECT_EQ (port, node->network.endpoint ().port ());
EXPECT_EQ (port, node->tcp_listener.endpoint ().port ());
Expand All @@ -79,7 +79,7 @@ TEST (network, send_node_id_handshake_tcp)
nano::test::system system (1);
auto node0 (system.nodes[0]);
ASSERT_EQ (0, node0->network.size ());
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
node1->start ();
system.nodes.push_back (node1);
auto initial (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in));
Expand Down Expand Up @@ -157,15 +157,15 @@ TEST (network, multi_keepalive)
nano::test::system system (1);
auto node0 = system.nodes[0];
ASSERT_EQ (0, node0->network.size ());
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node1->init_error ());
node1->start ();
system.nodes.push_back (node1);
ASSERT_EQ (0, node1->network.size ());
ASSERT_EQ (0, node0->network.size ());
node1->network.tcp_channels.start_tcp (node0->network.endpoint ());
ASSERT_TIMELY (10s, node0->network.size () == 1 && node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive) >= 1);
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
ASSERT_FALSE (node2->init_error ());
node2->start ();
system.nodes.push_back (node2);
Expand Down Expand Up @@ -749,7 +749,7 @@ TEST (network, peer_max_tcp_attempts)
auto node = system.add_node (node_flags);
for (auto i (0); i < node->network_params.network.max_peers_per_ip; ++i)
{
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work, node_flags));
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work, node_flags));
node2->start ();
system.nodes.push_back (node2);
// Start TCP attempt
Expand Down Expand Up @@ -826,7 +826,7 @@ TEST (network, duplicate_revert_publish)
nano::uint128_t digest;
ASSERT_FALSE (node.network.publish_filter.apply (bytes.data (), bytes.size (), &digest));
ASSERT_TRUE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
auto other_node (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto other_node (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
other_node->start ();
system.nodes.push_back (other_node);
auto channel = nano::test::establish_tcp (system, *other_node, node.network.endpoint ());
Expand Down Expand Up @@ -957,7 +957,7 @@ TEST (network, tcp_no_connect_excluded_peers)
nano::test::system system (1);
auto node0 (system.nodes[0]);
ASSERT_EQ (0, node0->network.size ());
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node1 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
node1->start ();
system.nodes.push_back (node1);
auto endpoint1_tcp (nano::transport::map_endpoint_to_tcp (node1->network.endpoint ()));
Expand Down Expand Up @@ -1058,7 +1058,7 @@ TEST (network, cleanup_purge)
nano::test::system system (1);
auto & node1 (*system.nodes[0]);

auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.logging, system.work));
auto node2 (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
node2->start ();
system.nodes.push_back (node2);

Expand Down
Loading

0 comments on commit addcd24

Please sign in to comment.