Access Journal::Stream using member functions (RIPD-1087):

Replace Journal public data members with member function accessors
in order to make Journal lighter weight.  The change makes a
Journal cheaper to pass by value.

Also add missing stream checks (e.g., calls to JLOG) to avoid
text processing that ultimately will not be stored in the log.
This commit is contained in:
Scott Schurr
2016-03-09 10:48:21 -08:00
committed by seelabs
parent b3f5986c83
commit 7a4bd2278d
132 changed files with 1843 additions and 1799 deletions

View File

@@ -178,7 +178,7 @@ public:
void httpsNext ()
{
JLOG (j_.trace) << "Fetch: " << mDeqSites[0];
JLOG (j_.trace()) << "Fetch: " << mDeqSites[0];
auto query = std::make_shared<boost::asio::ip::tcp::resolver::query>(
mDeqSites[0],
@@ -188,7 +188,7 @@ public:
mDeadline.expires_from_now (mTimeout, mShutdown);
JLOG (j_.trace) << "expires_from_now: " << mShutdown.message ();
JLOG (j_.trace()) << "expires_from_now: " << mShutdown.message ();
if (!mShutdown)
{
@@ -201,7 +201,7 @@ public:
if (!mShutdown)
{
JLOG (j_.trace) << "Resolving: " << mDeqSites[0];
JLOG (j_.trace()) << "Resolving: " << mDeqSites[0];
mResolver.async_resolve (*mQuery,
std::bind (
@@ -220,20 +220,20 @@ public:
if (ecResult == boost::asio::error::operation_aborted)
{
// Timer canceled because deadline no longer needed.
JLOG (j_.trace) << "Deadline cancelled.";
JLOG (j_.trace()) << "Deadline cancelled.";
// Aborter is done.
}
else if (ecResult)
{
JLOG (j_.trace) << "Deadline error: " << mDeqSites[0] << ": " << ecResult.message ();
JLOG (j_.trace()) << "Deadline error: " << mDeqSites[0] << ": " << ecResult.message ();
// Can't do anything sound.
abort ();
}
else
{
JLOG (j_.trace) << "Deadline arrived.";
JLOG (j_.trace()) << "Deadline arrived.";
// Mark us as shutting down.
// XXX Use our own error code.
@@ -257,7 +257,7 @@ public:
{
if (ecResult)
{
JLOG (j_.trace) << "Shutdown error: " << mDeqSites[0] << ": " << ecResult.message ();
JLOG (j_.trace()) << "Shutdown error: " << mDeqSites[0] << ": " << ecResult.message ();
}
}
@@ -271,13 +271,13 @@ public:
if (mShutdown)
{
JLOG (j_.trace) << "Resolve error: " << mDeqSites[0] << ": " << mShutdown.message ();
JLOG (j_.trace()) << "Resolve error: " << mDeqSites[0] << ": " << mShutdown.message ();
invokeComplete (mShutdown);
}
else
{
JLOG (j_.trace) << "Resolve complete.";
JLOG (j_.trace()) << "Resolve complete.";
boost::asio::async_connect (
mSocket.lowest_layer (),
@@ -296,12 +296,12 @@ public:
if (mShutdown)
{
JLOG (j_.trace) << "Connect error: " << mShutdown.message ();
JLOG (j_.trace()) << "Connect error: " << mShutdown.message ();
}
if (!mShutdown)
{
JLOG (j_.trace) << "Connected.";
JLOG (j_.trace()) << "Connected.";
if (httpClientSSLContext->sslVerify ())
{
@@ -309,7 +309,7 @@ public:
if (mShutdown)
{
JLOG (j_.trace) << "set_verify_callback: " << mDeqSites[0] << ": " << mShutdown.message ();
JLOG (j_.trace()) << "set_verify_callback: " << mDeqSites[0] << ": " << mShutdown.message ();
}
}
}
@@ -340,13 +340,13 @@ public:
if (mShutdown)
{
JLOG (j_.trace) << "Handshake error:" << mShutdown.message ();
JLOG (j_.trace()) << "Handshake error:" << mShutdown.message ();
invokeComplete (mShutdown);
}
else
{
JLOG (j_.trace) << "Session started.";
JLOG (j_.trace()) << "Session started.";
mBuild (mRequest, mDeqSites[0]);
@@ -366,13 +366,13 @@ public:
if (mShutdown)
{
JLOG (j_.trace) << "Write error: " << mShutdown.message ();
JLOG (j_.trace()) << "Write error: " << mShutdown.message ();
invokeComplete (mShutdown);
}
else
{
JLOG (j_.trace) << "Wrote.";
JLOG (j_.trace()) << "Wrote.";
mSocket.async_read_until (
mHeader,
@@ -387,7 +387,7 @@ public:
void handleHeader (const boost::system::error_code& ecResult, std::size_t bytes_transferred)
{
std::string strHeader ((std::istreambuf_iterator<char> (&mHeader)), std::istreambuf_iterator<char> ());
JLOG (j_.trace) << "Header: \"" << strHeader << "\"";
JLOG (j_.trace()) << "Header: \"" << strHeader << "\"";
static boost::regex reStatus ("\\`HTTP/1\\S+ (\\d{3}) .*\\'"); // HTTP/1.1 200 OK
static boost::regex reSize ("\\`.*\\r\\nContent-Length:\\s+([0-9]+).*\\'");
@@ -400,7 +400,7 @@ public:
if (!bMatch)
{
// XXX Use our own error code.
JLOG (j_.trace) << "No status code";
JLOG (j_.trace()) << "No status code";
invokeComplete (boost::system::error_code (boost::system::errc::bad_address, boost::system::system_category ()));
return;
}
@@ -447,7 +447,7 @@ public:
if (mShutdown && mShutdown != boost::asio::error::eof)
{
JLOG (j_.trace) << "Read error: " << mShutdown.message ();
JLOG (j_.trace()) << "Read error: " << mShutdown.message ();
invokeComplete (mShutdown);
}
@@ -455,7 +455,7 @@ public:
{
if (mShutdown)
{
JLOG (j_.trace) << "Complete.";
JLOG (j_.trace()) << "Complete.";
}
else
{
@@ -475,10 +475,10 @@ public:
if (ecCancel)
{
JLOG (j_.trace) << "invokeComplete: Deadline cancel error: " << ecCancel.message ();
JLOG (j_.trace()) << "invokeComplete: Deadline cancel error: " << ecCancel.message ();
}
JLOG (j_.debug) << "invokeComplete: Deadline popping: " << mDeqSites.size ();
JLOG (j_.debug()) << "invokeComplete: Deadline popping: " << mDeqSites.size ();
if (!mDeqSites.empty ())
{

View File

@@ -478,8 +478,8 @@ private:
Json::Reader reader;
Json::Value jvRequest;
JLOG (j_.trace) << "RPC method: " << jvParams[0u];
JLOG (j_.trace) << "RPC json: " << jvParams[1u];
JLOG (j_.trace()) << "RPC method: " << jvParams[0u];
JLOG (j_.trace()) << "RPC json: " << jvParams[1u];
if (reader.parse (jvParams[1u].asString (), jvRequest))
{
@@ -635,7 +635,7 @@ private:
Json::Value jvRequest;
bool bLedger = 2 == jvParams.size ();
JLOG (j_.trace) << "RPC json: " << jvParams[0u];
JLOG (j_.trace()) << "RPC json: " << jvParams[0u];
if (reader.parse (jvParams[0u].asString (), jvRequest))
{
@@ -893,10 +893,10 @@ public:
// <-- { method: xyz, params: [... ] } or { error: ..., ... }
Json::Value parseCommand (std::string strMethod, Json::Value jvParams, bool allowAnyCommand)
{
if (j_.trace)
if (auto stream = j_.trace())
{
j_.trace << "Method: '" << strMethod << "'";
j_.trace << "Params: " << jvParams;
stream << "Method: '" << strMethod << "'";
stream << "Params: " << jvParams;
}
struct Command
@@ -983,7 +983,7 @@ public:
if ((command.minParams >= 0 && count < command.minParams) ||
(command.maxParams >= 0 && count > command.maxParams))
{
JLOG (j_.debug) <<
JLOG (j_.debug()) <<
"Wrong number of parameters for " << command.name <<
" minimum=" << command.minParams <<
" maximum=" << command.maxParams <<
@@ -1054,7 +1054,7 @@ struct RPCCallImp
Throw<std::runtime_error> ("no response from server");
// Parse reply
JLOG (j.debug) << "RPC reply: " << strData << std::endl;
JLOG (j.debug()) << "RPC reply: " << strData << std::endl;
Json::Reader reader;
Json::Value jvReply;
@@ -1080,7 +1080,7 @@ struct RPCCallImp
const std::map<std::string, std::string>& mHeaders, std::string const& strPath,
boost::asio::streambuf& sb, std::string const& strHost, beast::Journal j)
{
JLOG (j.debug) << "requestRPC: strPath='" << strPath << "'";
JLOG (j.debug()) << "requestRPC: strPath='" << strPath << "'";
std::ostream osRequest (&sb);
osRequest <<
@@ -1114,7 +1114,7 @@ rpcCmdLineToJson (std::vector<std::string> const& args,
jvRequest = rpParser.parseCommand (args[0], jvRpcParams, true);
JLOG (j.trace) << "RPC Request: " << jvRequest << std::endl;
JLOG (j.trace()) << "RPC Request: " << jvRequest << std::endl;
return jvRequest;
}

View File

@@ -61,7 +61,7 @@ public:
if (mPort < 0)
mPort = mSSL ? 443 : 80;
JLOG (j_.info) <<
JLOG (j_.info()) <<
"RPCCall::fromNetwork sub: ip=" << mIp <<
" port=" << mPort <<
" ssl= "<< (mSSL ? "yes" : "no") <<
@@ -79,11 +79,11 @@ public:
if (mDeque.size () >= eventQueueMax)
{
// Drop the previous event.
JLOG (j_.warning) << "RPCCall::fromNetwork drop";
JLOG (j_.warn()) << "RPCCall::fromNetwork drop";
mDeque.pop_back ();
}
auto& jm = broadcast ? j_.debug : j_.info;
auto jm = broadcast ? j_.debug() : j_.info();
JLOG (jm) <<
"RPCCall::fromNetwork push: " << jvObj;
@@ -94,7 +94,7 @@ public:
// Start a sending thread.
mSending = true;
JLOG (j_.info) << "RPCCall::fromNetwork start";
JLOG (j_.info()) << "RPCCall::fromNetwork start";
m_jobQueue.addJob (
jtCLIENT, "RPCSub::sendThread", [this] (Job&) {
@@ -154,7 +154,7 @@ private:
// XXX Might not need this in a try.
try
{
JLOG (j_.info) << "RPCCall::fromNetwork: " << mIp;
JLOG (j_.info()) << "RPCCall::fromNetwork: " << mIp;
RPCCall::fromNetwork (
m_io_service,
@@ -168,7 +168,7 @@ private:
}
catch (const std::exception& e)
{
JLOG (j_.info) << "RPCCall::fromNetwork exception: " << e.what ();
JLOG (j_.info()) << "RPCCall::fromNetwork exception: " << e.what ();
}
}
}