diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp index 018bfd8d74..a3306e4f33 100644 --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -169,11 +169,12 @@ void rai::rpc::stop () acceptor.close (); } -rai::rpc_handler::rpc_handler (rai::node & node_a, rai::rpc & rpc_a, std::string const & body_a, std::function const & response_a) : +rai::rpc_handler::rpc_handler (rai::node & node_a, rai::rpc & rpc_a, std::string const & body_a, std::string const & request_id_a, std::function const & response_a) : body (body_a), node (node_a), rpc (rpc_a), -response (response_a) +response (response_a), +request_id (request_id_a) { } @@ -4537,7 +4538,8 @@ void rai::rpc_connection::read () this_l->node->background ([this_l]() { auto start (std::chrono::steady_clock::now ()); auto version (this_l->request.version ()); - auto response_handler ([this_l, version, start](boost::property_tree::ptree const & tree_a) { + std::string request_id (boost::str (boost::format ("%1%") % boost::io::group (std::hex, std::showbase, reinterpret_cast (this_l.get ())))); + auto response_handler ([this_l, version, start, request_id](boost::property_tree::ptree const & tree_a) { std::stringstream ostream; boost::property_tree::write_json (ostream, tree_a); @@ -4549,12 +4551,12 @@ void rai::rpc_connection::read () if (this_l->node->config.logging.log_rpc ()) { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast (this_l.get ()))); + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count () % request_id); } }); if (this_l->request.method () == boost::beast::http::verb::post) { - auto handler (std::make_shared (*this_l->node, this_l->rpc, this_l->request.body (), response_handler)); + auto handler (std::make_shared (*this_l->node, this_l->rpc, this_l->request.body (), request_id, response_handler)); handler->process_request (); } else @@ -4607,7 +4609,7 @@ void rai::rpc_handler::process_request () } if (node.config.logging.log_rpc ()) { - BOOST_LOG (node.log) << body; + BOOST_LOG (node.log) << boost::str (boost::format ("%1% ") % request_id) << body; } if (action == "account_balance") { diff --git a/rai/node/rpc.hpp b/rai/node/rpc.hpp index af95c90dd7..b77769dcfc 100644 --- a/rai/node/rpc.hpp +++ b/rai/node/rpc.hpp @@ -112,7 +112,7 @@ class payment_observer : public std::enable_shared_from_this { public: - rpc_handler (rai::node &, rai::rpc &, std::string const &, std::function const &); + rpc_handler (rai::node &, rai::rpc &, std::string const &, std::string const &, std::function const &); void process_request (); void account_balance (); void account_block_count (); @@ -217,6 +217,7 @@ class rpc_handler : public std::enable_shared_from_this void work_peers (); void work_peers_clear (); std::string body; + std::string request_id; rai::node & node; rai::rpc & rpc; boost::property_tree::ptree request; diff --git a/rai/node/rpc_secure.cpp b/rai/node/rpc_secure.cpp index db11a12252..e5389e3ee1 100644 --- a/rai/node/rpc_secure.cpp +++ b/rai/node/rpc_secure.cpp @@ -152,7 +152,8 @@ void rai::rpc_connection_secure::read () this_l->node->background ([this_l]() { auto start (std::chrono::steady_clock::now ()); auto version (this_l->request.version ()); - auto response_handler ([this_l, version, start](boost::property_tree::ptree const & tree_a) { + std::string request_id (boost::str (boost::format ("%1%") % boost::io::group (std::hex, std::showbase, reinterpret_cast (this_l.get ())))); + auto response_handler ([this_l, version, start, request_id](boost::property_tree::ptree const & tree_a) { std::stringstream ostream; boost::property_tree::write_json (ostream, tree_a); ostream.flush (); @@ -171,13 +172,13 @@ void rai::rpc_connection_secure::read () if (this_l->node->config.logging.log_rpc ()) { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("TLS: RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast (this_l.get ()))); + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("TLS: RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count () % request_id); } }); if (this_l->request.method () == boost::beast::http::verb::post) { - auto handler (std::make_shared (*this_l->node, this_l->rpc, this_l->request.body (), response_handler)); + auto handler (std::make_shared (*this_l->node, this_l->rpc, this_l->request.body (), request_id, response_handler)); handler->process_request (); } else