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

@@ -236,7 +236,7 @@ BaseHTTPPeer<Impl>::BaseHTTPPeer (Port const& port, Handler& handler,
static std::atomic <int> sid;
nid_ = ++sid;
id_ = std::string("#") + std::to_string(nid_) + " ";
JLOG(journal_.trace) << id_ <<
JLOG(journal_.trace()) << id_ <<
"accept: " << remote_address_.address();
when_ = clock_type::now();
}
@@ -245,7 +245,7 @@ template <class Impl>
BaseHTTPPeer<Impl>::~BaseHTTPPeer()
{
handler_.onClose(session(), ec_);
JLOG(journal_.trace) << id_ <<
JLOG(journal_.trace()) << id_ <<
"destroyed: " << request_count_ <<
((request_count_ == 1) ? " request" : " requests");
}
@@ -271,7 +271,7 @@ BaseHTTPPeer<Impl>::fail (error_code ec, char const* what)
if (! ec_ && ec != boost::asio::error::operation_aborted)
{
ec_ = ec;
JLOG(journal_.trace) << id_ <<
JLOG(journal_.trace()) << id_ <<
std::string(what) << ": " << ec.message();
impl().stream_.lowest_layer().close (ec);
}

View File

@@ -155,7 +155,7 @@ Door::Detector::do_detect (boost::asio::yield_context yield)
}
if (ec != boost::asio::error::operation_aborted)
{
JLOG(j_.trace) <<
JLOG(j_.trace()) <<
"Error detecting ssl: " << ec.message() <<
" from " << remote_address_;
}
@@ -185,7 +185,7 @@ Door::Door (Handler& handler, boost::asio::io_service& io_service,
acceptor_.open(local_address.protocol(), ec);
if (ec)
{
JLOG(j_.error) <<
JLOG(j_.error()) <<
"Open port '" << port.name << "' failed:" << ec.message();
Throw<std::exception> ();
}
@@ -194,7 +194,7 @@ Door::Door (Handler& handler, boost::asio::io_service& io_service,
boost::asio::ip::tcp::acceptor::reuse_address(true), ec);
if (ec)
{
JLOG(j_.error) <<
JLOG(j_.error()) <<
"Option for port '" << port.name << "' failed:" << ec.message();
Throw<std::exception> ();
}
@@ -202,7 +202,7 @@ Door::Door (Handler& handler, boost::asio::io_service& io_service,
acceptor_.bind(local_address, ec);
if (ec)
{
JLOG(j_.error) <<
JLOG(j_.error()) <<
"Bind port '" << port.name << "' failed:" << ec.message();
Throw<std::exception> ();
}
@@ -210,12 +210,12 @@ Door::Door (Handler& handler, boost::asio::io_service& io_service,
acceptor_.listen(boost::asio::socket_base::max_connections, ec);
if (ec)
{
JLOG(j_.error) <<
JLOG(j_.error()) <<
"Listen on port '" << port.name << "' failed:" << ec.message();
Throw<std::exception> ();
}
JLOG(j_.info) <<
JLOG(j_.info()) <<
"Opened " << port;
}
@@ -267,8 +267,10 @@ Door::do_accept (boost::asio::yield_context yield)
socket_type socket (acceptor_.get_io_service());
acceptor_.async_accept (socket, remote_address, yield[ec]);
if (ec && ec != boost::asio::error::operation_aborted)
if (j_.error) j_.error <<
{
JLOG(j_.error()) <<
"accept: " << ec.message();
}
if (ec == boost::asio::error::operation_aborted)
break;
if (ec)

View File

@@ -46,7 +46,7 @@ std::string getHTTPHeaderTimestamp ()
void HTTPReply (
int nStatus, std::string const& content, Json::Output const& output, beast::Journal j)
{
JLOG (j.trace)
JLOG (j.trace())
<< "HTTP Reply " << nStatus << " " << content;
if (nStatus == 401)

View File

@@ -355,11 +355,11 @@ ServerHandlerImp::processRequest (Port const& port,
return;
}
JLOG(m_journal.debug) << "Query: " << strMethod << params;
JLOG(m_journal.debug()) << "Query: " << strMethod << params;
// Provide the JSON-RPC method as the field "command" in the request.
params[jss::command] = strMethod;
JLOG (m_journal.trace)
JLOG (m_journal.trace())
<< "doRpcCommand:" << strMethod << ":" << params;
Resource::Charge loadType = Resource::feeReferenceRPC;
@@ -376,7 +376,7 @@ ServerHandlerImp::processRequest (Port const& port,
{
result[jss::status] = jss::error;
result[jss::request] = params;
JLOG (m_journal.debug) <<
JLOG (m_journal.debug()) <<
"rpcError: " << result [jss::error] <<
": " << result [jss::error_message];
}
@@ -399,13 +399,13 @@ ServerHandlerImp::processRequest (Port const& port,
response += '\n';
usage.charge (loadType);
if (m_journal.debug.active())
if (auto stream = m_journal.debug())
{
static const int maxSize = 10000;
if (response.size() <= maxSize)
m_journal.debug << "Reply: " << response;
stream << "Reply: " << response;
else
m_journal.debug << "Reply: " << response.substr (0, maxSize);
stream << "Reply: " << response.substr (0, maxSize);
}
HTTPReply (200, response, output, rpcJ);

View File

@@ -77,13 +77,13 @@ public:
public:
TestSink (beast::unit_test::suite& suite)
: Sink (beast::Journal::kWarning, false)
: Sink (beast::severities::kWarning, false)
, suite_ (suite)
{
}
void
write (beast::Journal::Severity level,
write (beast::severities::Severity level,
std::string const& text) override
{
if (level < threshold())
@@ -279,7 +279,7 @@ public:
{
TestSink sink {*this};
TestThread thread;
sink.threshold (beast::Journal::Severity::kAll);
sink.threshold (beast::severities::Severity::kAll);
beast::Journal journal {sink};
TestHandler handler;
auto s = make_Server (handler,