diff --git a/nano/core_test/core_test_main.cc b/nano/core_test/core_test_main.cc index 2710b0f8a6..c2f2d22136 100644 --- a/nano/core_test/core_test_main.cc +++ b/nano/core_test/core_test_main.cc @@ -19,7 +19,7 @@ void force_nano_dev_network (); GTEST_API_ int main (int argc, char ** argv) { - nano::initialize_logging (nano::log::preset::tests); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ())); 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; diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index fb3ce48e9f..f722b0e66a 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -403,10 +404,12 @@ nano::tomlconfig nano::load_toml_file (const std::filesystem::path & config_file // First try to load config from the current working directory, then from the node data directory if (auto toml = try_load_toml (config_filename); toml) { + nano::default_logger ().info (nano::log::type::config, "Config for `{}` loaded from current working directory", config_filename.string ()); return *toml; } if (auto toml = try_load_toml (data_path / config_filename); toml) { + nano::default_logger ().info (nano::log::type::config, "Config for `{}` loaded from node data directory ({})", config_filename.string (), data_path.string ()); return *toml; } @@ -417,5 +420,6 @@ nano::tomlconfig nano::load_toml_file (const std::filesystem::path & config_file { throw std::runtime_error (error.get_message ()); } + nano::default_logger ().info (nano::log::type::config, "Config for `{}` not found, using default configuration", config_filename.string ()); return toml; } diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index 858104a60e..ea26bee3c6 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -491,7 +491,7 @@ account_info account_info_rpc (boost::asio::io_context & ioc, tcp::resolver::res /** This launches a node and fires a lot of send/recieve RPC requests at it (configurable), then other nodes are tested to make sure they observe these blocks as well. */ int main (int argc, char * const * argv) { - nano::initialize_logging (nano::log::preset::tests); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ())); nano::force_nano_dev_network (); boost::program_options::options_description description ("Command line options"); diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 277eb8726b..08b5108384 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -63,7 +63,7 @@ constexpr std::size_t OPEN_FILE_DESCRIPTORS_LIMIT = 16384; void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flags const & flags) { - nano::initialize_logging (nano::log::preset::daemon); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::daemon_default (), data_path, flags.config_overrides)); nlogger.info (nano::log::type::daemon, "Daemon started"); @@ -72,6 +72,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag std::filesystem::create_directories (data_path); boost::system::error_code error_chmod; nano::set_secure_perm_directory (data_path, error_chmod); + std::unique_ptr runner; nano::network_params network_params{ nano::network_constants::active_network }; nano::daemon_config config{ data_path, network_params }; @@ -229,5 +230,5 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag nlogger.critical (nano::log::type::daemon, "Error deserializing config: {}", error.get_message ()); } - nlogger.info (nano::log::type::daemon, "Daemon exiting..."); + nlogger.info (nano::log::type::daemon, "Daemon exiting"); } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index cf0b369847..bee3d44e06 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -53,8 +53,8 @@ class address_library_pair int main (int argc, char * const * argv) { - nano::set_umask (); - nano::initialize_logging (); + nano::set_umask (); // Make sure the process umask is set before any files are created + nano::nlogger::initialize (nano::log_config::cli_default ()); nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; diff --git a/nano/nano_rpc/entry.cpp b/nano/nano_rpc/entry.cpp index fd310d7d63..1238c95ce3 100644 --- a/nano/nano_rpc/entry.cpp +++ b/nano/nano_rpc/entry.cpp @@ -17,19 +17,19 @@ namespace { -nano::nlogger nlogger; - volatile sig_atomic_t sig_int_or_term = 0; +nano::nlogger nlogger{ "rpc_daemon" }; + void run (std::filesystem::path const & data_path, std::vector const & config_overrides) { - nano::initialize_logging (nano::log::preset::daemon); - - nlogger.info (nano::log::type::daemon, "Daemon started (RPC)"); + nlogger.info (nano::log::type::daemon_rpc, "Daemon started (RPC)"); std::filesystem::create_directories (data_path); + boost::system::error_code error_chmod; nano::set_secure_perm_directory (data_path, error_chmod); + std::unique_ptr runner; nano::network_params network_params{ nano::network_constants::active_network }; @@ -83,13 +83,15 @@ void run (std::filesystem::path const & data_path, std::vector cons { nlogger.critical (nano::log::type::daemon, "Error deserializing config: {}", error.get_message ()); } + + nlogger.info (nano::log::type::daemon_rpc, "Daemon stopped (RPC)"); } } int main (int argc, char * const * argv) { - nano::set_umask (); - nano::initialize_logging (); + nano::set_umask (); // Make sure the process umask is set before any files are created + nano::nlogger::initialize (nano::log_config::cli_default ()); boost::program_options::options_description description ("Command line options"); diff --git a/nano/nano_wallet/entry.cpp b/nano/nano_wallet/entry.cpp index e767ef4fd1..04e55e14d2 100644 --- a/nano/nano_wallet/entry.cpp +++ b/nano/nano_wallet/entry.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,7 @@ namespace { -nano::nlogger nlogger; +nano::nlogger nlogger{ "wallet_daemon" }; void show_error (std::string const & message_a) { @@ -73,9 +74,9 @@ nano::error read_wallet_config (nano::wallet_config & config_a, std::filesystem: int run_wallet (QApplication & application, int argc, char * const * argv, std::filesystem::path const & data_path, nano::node_flags const & flags) { - nano::initialize_logging (nano::log::preset::daemon); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::daemon_default (), data_path, flags.config_overrides)); - nlogger.info (nano::log::type::daemon, "Daemon started (wallet)"); + nlogger.info (nano::log::type::daemon_wallet, "Daemon started (wallet)"); int result (0); nano_qt::eventloop_processor processor; @@ -237,13 +238,16 @@ int run_wallet (QApplication & application, int argc, char * const * argv, std:: splash->hide (); show_error ("Error deserializing config: " + error.get_message ()); } + + nlogger.info (nano::log::type::daemon_wallet, "Daemon exiting (wallet)"); + return result; } int main (int argc, char * const * argv) { - nano::set_umask (); - nano::initialize_logging (); + nano::set_umask (); // Make sure the process umask is set before any files are created + nano::nlogger::initialize (nano::log_config::cli_default ()); nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 431f7b397f..9ec0539b4c 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -254,8 +254,6 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map if (vm.count ("initialize")) { - nano::initialize_logging (nano::log::preset::daemon); - auto node_flags = nano::inactive_node_flag_defaults (); node_flags.read_only = false; nano::update_flags (node_flags, vm); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 9908c22d9b..41322c4bde 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -144,6 +144,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons node_initialized_latch (1), config (config_a), network_params{ config.network_params }, + nlogger{ "node" }, stats (config.stats_config), workers{ config.background_threads, nano::thread_role::name::worker }, bootstrap_workers{ config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker }, @@ -1484,13 +1485,14 @@ nano::node_wrapper::node_wrapper (std::filesystem::path const & path_a, std::fil io_context (std::make_shared ()), work{ network_params.network, 1 } { - boost::system::error_code error_chmod; - /* * @warning May throw a filesystem exception */ std::filesystem::create_directories (path_a); + + boost::system::error_code error_chmod; nano::set_secure_perm_directory (path_a, error_chmod); + nano::daemon_config daemon_config{ path_a, network_params }; auto error = nano::read_node_config_toml (config_path_a, daemon_config, node_flags_a.config_overrides); if (error) diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 5e3fe7e037..e656ad60d5 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -69,9 +69,6 @@ outbound_bandwidth_limiter::config outbound_bandwidth_limiter_config (node_confi class node final : public std::enable_shared_from_this { -public: - nano::nlogger nlogger; - public: node (boost::asio::io_context &, uint16_t, std::filesystem::path const &, nano::work_pool &, nano::node_flags = nano::node_flags (), unsigned seq = 0); node (boost::asio::io_context &, std::filesystem::path const &, nano::node_config const &, nano::work_pool &, nano::node_flags = nano::node_flags (), unsigned seq = 0); @@ -148,6 +145,7 @@ class node final : public std::enable_shared_from_this boost::latch node_initialized_latch; nano::node_config config; nano::network_params & network_params; + nano::nlogger nlogger; nano::stats stats; nano::thread_pool workers; nano::thread_pool bootstrap_workers; diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 561a844dc0..c4f8a9693b 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ class node_config bool upgrade_json (unsigned, nano::jsonconfig &); nano::account random_representative () const; + nano::network_params network_params; std::optional peering_port{}; nano::scheduler::optimistic_config optimistic_scheduler; diff --git a/nano/qt_test/entry.cpp b/nano/qt_test/entry.cpp index 9b05a964bd..6208cbb229 100644 --- a/nano/qt_test/entry.cpp +++ b/nano/qt_test/entry.cpp @@ -17,7 +17,7 @@ void force_nano_dev_network (); int main (int argc, char ** argv) { - nano::initialize_logging (nano::log::preset::tests); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ())); nano::force_nano_dev_network (); nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; QApplication application (argc, argv); diff --git a/nano/rpc/rpc.hpp b/nano/rpc/rpc.hpp index 2f4bcb115e..695de1467a 100644 --- a/nano/rpc/rpc.hpp +++ b/nano/rpc/rpc.hpp @@ -31,7 +31,7 @@ class rpc return acceptor.local_endpoint ().port (); } - nano::nlogger nlogger; + nano::nlogger nlogger{ "rpc" }; nano::rpc_config config; boost::asio::ip::tcp::acceptor acceptor; boost::asio::io_context & io_ctx; diff --git a/nano/rpc_test/entry.cpp b/nano/rpc_test/entry.cpp index e04e9398f9..3f81484360 100644 --- a/nano/rpc_test/entry.cpp +++ b/nano/rpc_test/entry.cpp @@ -15,7 +15,7 @@ void force_nano_dev_network (); int main (int argc, char ** argv) { - nano::initialize_logging (nano::log::preset::tests); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ())); nano::force_nano_dev_network (); nano::set_use_memory_pools (false); nano::node_singleton_memory_pool_purge_guard cleanup_guard; diff --git a/nano/slow_test/entry.cpp b/nano/slow_test/entry.cpp index db177c24cd..d7cf3c6846 100644 --- a/nano/slow_test/entry.cpp +++ b/nano/slow_test/entry.cpp @@ -14,7 +14,7 @@ void force_nano_dev_network (); int main (int argc, char ** argv) { - nano::initialize_logging (nano::log::preset::tests); + nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ())); nano::force_nano_dev_network (); nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; testing::InitGoogleTest (&argc, argv); diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index b8b9706e94..d3ce60c373 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -618,10 +618,9 @@ uint16_t nano::test::system::get_available_port (bool can_be_zero) } } +// Makes sure everything is cleaned up void nano::test::cleanup_dev_directories_on_exit () { - // Makes sure everything is cleaned up - nano::logging::release_file_sink (); // Clean up tmp directories created by the tests. Since it's sometimes useful to // see log files after test failures, an environment variable is supported to // retain the files.