diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 9ce9322e7e..df5b2ca33e 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -104,6 +104,8 @@ TEST (toml, rpc_config_deserialize_defaults) ASSERT_EQ (conf.rpc_process.ipc_address, defaults.rpc_process.ipc_address); ASSERT_EQ (conf.rpc_process.ipc_port, defaults.rpc_process.ipc_port); ASSERT_EQ (conf.rpc_process.num_ipc_connections, defaults.rpc_process.num_ipc_connections); + + ASSERT_EQ (conf.rpc_logging.log_rpc, defaults.rpc_logging.log_rpc); } /** Empty config file should match a default config object */ @@ -725,6 +727,8 @@ TEST (toml, rpc_config_deserialize_no_defaults) ipc_address = "0:0:0:0:0:ffff:7f01:101" ipc_port = 999 num_ipc_connections = 999 + [logging] + log_rpc = false )toml"; nano::tomlconfig toml; @@ -745,6 +749,8 @@ TEST (toml, rpc_config_deserialize_no_defaults) ASSERT_NE (conf.rpc_process.ipc_address, defaults.rpc_process.ipc_address); ASSERT_NE (conf.rpc_process.ipc_port, defaults.rpc_process.ipc_port); ASSERT_NE (conf.rpc_process.num_ipc_connections, defaults.rpc_process.num_ipc_connections); + + ASSERT_NE (conf.rpc_logging.log_rpc, defaults.rpc_logging.log_rpc); } /** There should be no required values **/ @@ -756,6 +762,7 @@ TEST (toml, rpc_config_no_required) ss << R"toml( [version] [process] + [logging] [secure] )toml"; diff --git a/nano/lib/rpcconfig.cpp b/nano/lib/rpcconfig.cpp index da6fbc1a79..262c9f61e7 100644 --- a/nano/lib/rpcconfig.cpp +++ b/nano/lib/rpcconfig.cpp @@ -165,6 +165,10 @@ nano::error nano::rpc_config::serialize_toml (nano::tomlconfig & toml) const rpc_process_l.put ("ipc_port", rpc_process.ipc_port, "Listening port of IPC server.\ntype:uint16"); rpc_process_l.put ("num_ipc_connections", rpc_process.num_ipc_connections, "Number of IPC connections to establish.\ntype:uint32"); toml.put_child ("process", rpc_process_l); + + nano::tomlconfig rpc_logging_l; + rpc_logging_l.put ("log_rpc", rpc_logging.log_rpc, "Whether to log RPC calls.\ntype:bool"); + toml.put_child ("logging", rpc_logging_l); return toml.get_error (); } @@ -186,6 +190,12 @@ nano::error nano::rpc_config::deserialize_toml (nano::tomlconfig & toml) toml.get_optional ("max_json_depth", max_json_depth); toml.get_optional ("max_request_size", max_request_size); + auto rpc_logging_l (toml.get_optional_child ("logging")); + if (rpc_logging_l) + { + rpc_logging_l->get_optional ("log_rpc", rpc_logging.log_rpc); + } + auto rpc_process_l (toml.get_optional_child ("process")); if (rpc_process_l) { diff --git a/nano/lib/rpcconfig.hpp b/nano/lib/rpcconfig.hpp index fe70405295..018e1e0a76 100644 --- a/nano/lib/rpcconfig.hpp +++ b/nano/lib/rpcconfig.hpp @@ -60,6 +60,12 @@ class rpc_process_config final } }; +class rpc_logging_config final +{ +public: + bool log_rpc{ true }; +}; + class rpc_config final { public: @@ -77,6 +83,7 @@ class rpc_config final rpc_secure_config secure; uint8_t max_json_depth{ 20 }; uint64_t max_request_size{ 32 * 1024 * 1024 }; + nano::rpc_logging_config rpc_logging; static unsigned json_version () { return 1; diff --git a/nano/rpc/rpc_connection.cpp b/nano/rpc/rpc_connection.cpp index 6cb1108b8a..b5b9e5b3f8 100644 --- a/nano/rpc/rpc_connection.cpp +++ b/nano/rpc/rpc_connection.cpp @@ -124,8 +124,11 @@ void nano::rpc_connection::parse_request (STREAM_TYPE & stream, std::shared_ptr< })); std::stringstream ss; - ss << "RPC request " << request_id << " completed in: " << std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count () << " microseconds"; - this_l->logger.always_log (ss.str ().c_str ()); + if (this_l->rpc_config.rpc_logging.log_rpc) + { + ss << "RPC request " << request_id << " completed in: " << std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count () << " microseconds"; + this_l->logger.always_log (ss.str ().c_str ()); + } }); std::string api_path_l = "/api/v2"; diff --git a/nano/rpc/rpc_handler.cpp b/nano/rpc/rpc_handler.cpp index 48979fac13..e372826d6e 100644 --- a/nano/rpc/rpc_handler.cpp +++ b/nano/rpc/rpc_handler.cpp @@ -60,10 +60,13 @@ void nano::rpc_handler::process_request (nano::rpc_handler_request_params const } auto action = request.get ("action"); - // Creating same string via stringstream as using it directly is generating a TSAN warning - std::stringstream ss; - ss << request_id; - logger.always_log (ss.str (), " ", filter_request (request)); + if (rpc_config.rpc_logging.log_rpc) + { + // Creating same string via stringstream as using it directly is generating a TSAN warning + std::stringstream ss; + ss << request_id; + logger.always_log (ss.str (), " ", filter_request (request)); + } // Check if this is a RPC command which requires RPC enabled control std::error_code rpc_control_disabled_ec = nano::error_rpc::rpc_control_disabled;