Fix wallet logging initialization (#4680)
* Adjust annoying logs * Wrap wallet logic in a class
This commit is contained in:
parent
e877de187b
commit
fbcabb2fc0
2 changed files with 188 additions and 182 deletions
|
|
@ -23,31 +23,34 @@
|
|||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
namespace
|
||||
namespace nano
|
||||
{
|
||||
nano::logger logger{ "wallet_daemon" };
|
||||
class wallet_daemon final
|
||||
{
|
||||
nano::logger logger{ "wallet_daemon" };
|
||||
|
||||
void show_error (std::string const & message_a)
|
||||
{
|
||||
public:
|
||||
void show_error (std::string const & message_a)
|
||||
{
|
||||
logger.critical (nano::log::type::daemon, "{}", message_a);
|
||||
|
||||
QMessageBox message (QMessageBox::Critical, "Error starting Nano", message_a.c_str ());
|
||||
message.setModal (true);
|
||||
message.show ();
|
||||
message.exec ();
|
||||
}
|
||||
}
|
||||
|
||||
void show_help (std::string const & message_a)
|
||||
{
|
||||
void show_help (std::string const & message_a)
|
||||
{
|
||||
QMessageBox message (QMessageBox::NoIcon, "Help", "see <a href=\"https://docs.nano.org/commands/command-line-interface/#launch-options\">launch options</a> ");
|
||||
message.setStyleSheet ("QLabel {min-width: 450px}");
|
||||
message.setDetailedText (message_a.c_str ());
|
||||
message.show ();
|
||||
message.exec ();
|
||||
}
|
||||
}
|
||||
|
||||
nano::error write_wallet_config (nano::wallet_config & config_a, std::filesystem::path const & data_path_a)
|
||||
{
|
||||
nano::error write_wallet_config (nano::wallet_config & config_a, std::filesystem::path const & data_path_a)
|
||||
{
|
||||
nano::tomlconfig wallet_config_toml;
|
||||
auto wallet_path (nano::get_qtwallet_toml_config_path (data_path_a));
|
||||
config_a.serialize_toml (wallet_config_toml);
|
||||
|
|
@ -55,10 +58,10 @@ nano::error write_wallet_config (nano::wallet_config & config_a, std::filesystem
|
|||
// Write wallet config. If missing, the file is created and permissions are set.
|
||||
wallet_config_toml.write (wallet_path);
|
||||
return wallet_config_toml.get_error ();
|
||||
}
|
||||
}
|
||||
|
||||
nano::error read_wallet_config (nano::wallet_config & config_a, std::filesystem::path const & data_path_a)
|
||||
{
|
||||
nano::error read_wallet_config (nano::wallet_config & config_a, std::filesystem::path const & data_path_a)
|
||||
{
|
||||
nano::tomlconfig wallet_config_toml;
|
||||
auto wallet_path (nano::get_qtwallet_toml_config_path (data_path_a));
|
||||
if (!std::filesystem::exists (wallet_path))
|
||||
|
|
@ -68,11 +71,10 @@ nano::error read_wallet_config (nano::wallet_config & config_a, std::filesystem:
|
|||
wallet_config_toml.read (wallet_path);
|
||||
config_a.deserialize_toml (wallet_config_toml);
|
||||
return wallet_config_toml.get_error ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int run_wallet (QApplication & application, int argc, char * const * argv, std::filesystem::path const & data_path, nano::node_flags const & flags)
|
||||
{
|
||||
int run_wallet (QApplication & application, int argc, char * const * argv, std::filesystem::path const & data_path, nano::node_flags const & flags)
|
||||
{
|
||||
nano::logger::initialize (nano::log_config::daemon_default (), data_path, flags.config_overrides);
|
||||
|
||||
logger.info (nano::log::type::daemon_wallet, "Daemon started (wallet)");
|
||||
|
|
@ -232,6 +234,8 @@ int run_wallet (QApplication & application, int argc, char * const * argv, std::
|
|||
logger.info (nano::log::type::daemon_wallet, "Daemon exiting (wallet)");
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main (int argc, char * const * argv)
|
||||
|
|
@ -244,6 +248,8 @@ int main (int argc, char * const * argv)
|
|||
|
||||
QApplication application (argc, const_cast<char **> (argv));
|
||||
|
||||
nano::wallet_daemon daemon;
|
||||
|
||||
try
|
||||
{
|
||||
boost::program_options::options_description description ("Command line options");
|
||||
|
|
@ -262,7 +268,7 @@ int main (int argc, char * const * argv)
|
|||
}
|
||||
catch (boost::program_options::error const & err)
|
||||
{
|
||||
show_error (err.what ());
|
||||
daemon.show_error (err.what ());
|
||||
return 1;
|
||||
}
|
||||
boost::program_options::notify (vm);
|
||||
|
|
@ -273,7 +279,7 @@ int main (int argc, char * const * argv)
|
|||
auto err (nano::network_constants::set_active_network (network->second.as<std::string> ()));
|
||||
if (err)
|
||||
{
|
||||
show_error (nano::network_constants::active_network_err_msg);
|
||||
daemon.show_error (nano::network_constants::active_network_err_msg);
|
||||
std::exit (1);
|
||||
}
|
||||
}
|
||||
|
|
@ -293,7 +299,7 @@ int main (int argc, char * const * argv)
|
|||
std::ostringstream outstream;
|
||||
description.print (outstream);
|
||||
std::string helpstring = outstream.str ();
|
||||
show_help (helpstring);
|
||||
daemon.show_help (helpstring);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
|
@ -316,15 +322,15 @@ int main (int argc, char * const * argv)
|
|||
{
|
||||
throw std::runtime_error (flags_ec.message ());
|
||||
}
|
||||
result = run_wallet (application, argc, argv, data_path, flags);
|
||||
result = daemon.run_wallet (application, argc, argv, data_path, flags);
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
show_error (boost::str (boost::format ("Exception while running wallet: %1%") % e.what ()));
|
||||
daemon.show_error (boost::str (boost::format ("Exception while running wallet: %1%") % e.what ()));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
show_error ("Unknown exception while running wallet");
|
||||
daemon.show_error ("Unknown exception while running wallet");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -332,11 +338,11 @@ int main (int argc, char * const * argv)
|
|||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
show_error (boost::str (boost::format ("Exception while initializing %1%") % e.what ()));
|
||||
daemon.show_error (boost::str (boost::format ("Exception while initializing %1%") % e.what ()));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
show_error (boost::str (boost::format ("Unknown exception while initializing")));
|
||||
daemon.show_error (boost::str (boost::format ("Unknown exception while initializing")));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a)
|
|||
build_region (uint128_t{ 1 } << 116, uint128_t{ 1 } << 120, 2);
|
||||
minimums.push_back (uint128_t{ 1 } << 120);
|
||||
|
||||
node.logger.info (nano::log::type::election_scheduler, "Number of buckets: {}", minimums.size ());
|
||||
node.logger.debug (nano::log::type::election_scheduler, "Number of buckets: {}", minimums.size ());
|
||||
|
||||
for (size_t i = 0u, n = minimums.size (); i < n; ++i)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue