Skip to content

Commit

Permalink
Merge pull request #1412 from AntelopeIO/GH-1279-print-options
Browse files Browse the repository at this point in the history
Print non-default options on startup/shutdown
  • Loading branch information
heifner authored Jul 18, 2023
2 parents d243f85 + 81a3a77 commit 98bbe9d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
49 changes: 48 additions & 1 deletion programs/nodeos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,57 @@
#include <fc/log/logger_config.hpp>
#include <fc/log/appender.hpp>
#include <fc/exception/exception.hpp>
#include <fc/scoped_exit.hpp>

#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/exception/diagnostic_information.hpp>

#include <filesystem>
#include <string>
#include <vector>
#include <iterator>

#include "config.hpp"

using namespace appbase;
using namespace eosio;

namespace detail {

void log_non_default_options(const std::vector<bpo::basic_option<char>>& options) {
using namespace std::string_literals;
string result;
for (const auto& op : options) {
bool mask = false;
if (op.string_key == "signature-provider"s
|| op.string_key == "peer-private-key"s
|| op.string_key == "p2p-auto-bp-peer"s) {
mask = true;
}
std::string v;
for (auto i = op.value.cbegin(), b = op.value.cbegin(), e = op.value.cend(); i != e; ++i) {
if (i != b)
v += ", ";
if (mask)
v += "***";
else
v += *i;
}

if (!result.empty())
result += ", ";

if (v.empty()) {
result += op.string_key;
} else {
result += op.string_key;
result += " = ";
result += v;
}
}
ilog("Non-default options: ${v}", ("v", result));
}

fc::logging_config& add_deep_mind_logger(fc::logging_config& config) {
config.appenders.push_back(
fc::appender_config( "deep-mind", "dmlog" )
Expand Down Expand Up @@ -109,6 +149,12 @@ int main(int argc, char** argv)
{
try {
appbase::scoped_app app;
fc::scoped_exit<std::function<void()>> on_exit = [&]() {
ilog("${name} version ${ver} ${fv}",
("name", nodeos::config::node_executable_name)("ver", app->version_string())
("fv", app->version_string() == app->full_version_string() ? "" : app->full_version_string()) );
::detail::log_non_default_options(app->get_parsed_options());
};
uint32_t short_hash = 0;
fc::from_hex(eosio::version::version_hash(), (char*)&short_hash, sizeof(short_hash));

Expand Down Expand Up @@ -137,11 +183,12 @@ int main(int argc, char** argv)
elog("resource_monitor_plugin failed to initialize");
return INITIALIZE_FAIL;
}
ilog( "${name} version ${ver} ${fv}",
ilog("${name} version ${ver} ${fv}",
("name", nodeos::config::node_executable_name)("ver", app->version_string())
("fv", app->version_string() == app->full_version_string() ? "" : app->full_version_string()) );
ilog("${name} using configuration file ${c}", ("name", nodeos::config::node_executable_name)("c", app->full_config_file_path().string()));
ilog("${name} data directory is ${d}", ("name", nodeos::config::node_executable_name)("d", app->data_dir().string()));
::detail::log_non_default_options(app->get_parsed_options());
app->startup();
app->set_thread_priority_max();
app->exec();
Expand Down

0 comments on commit 98bbe9d

Please sign in to comment.