mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 04:25:51 +00:00
Use log/journal instead of std::cerr (RIPD-1377):
Change some uses of std::cerr to log or cout.
This commit is contained in:
committed by
Edward Hennis
parent
b3eada1dc2
commit
e01f6e7455
@@ -1104,7 +1104,9 @@ bool ApplicationImp::setup()
|
|||||||
m_overlay->setupValidatorKeyManifests (*config_, getWalletDB ());
|
m_overlay->setupValidatorKeyManifests (*config_, getWalletDB ());
|
||||||
|
|
||||||
{
|
{
|
||||||
auto setup = setup_ServerHandler(*config_, std::cerr);
|
auto setup = setup_ServerHandler(
|
||||||
|
*config_,
|
||||||
|
beast::logstream { m_journal.error() });
|
||||||
setup.makeContexts();
|
setup.makeContexts();
|
||||||
serverHandler_->setup (setup, m_journal);
|
serverHandler_->setup (setup, m_journal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ SHAMapStoreImp::dbPaths()
|
|||||||
{
|
{
|
||||||
if (! boost::filesystem::is_directory (dbPath))
|
if (! boost::filesystem::is_directory (dbPath))
|
||||||
{
|
{
|
||||||
std::cerr << "node db path must be a directory. "
|
journal_.error() << "node db path must be a directory. "
|
||||||
<< dbPath.string();
|
<< dbPath.string();
|
||||||
Throw<std::runtime_error> (
|
Throw<std::runtime_error> (
|
||||||
"node db path must be a directory.");
|
"node db path must be a directory.");
|
||||||
@@ -494,7 +494,7 @@ SHAMapStoreImp::dbPaths()
|
|||||||
stateDbPathName /= dbName_;
|
stateDbPathName /= dbName_;
|
||||||
stateDbPathName += "*";
|
stateDbPathName += "*";
|
||||||
|
|
||||||
std::cerr << "state db error: " << std::endl
|
journal_.error() << "state db error: " << std::endl
|
||||||
<< " writableDbExists " << writableDbExists
|
<< " writableDbExists " << writableDbExists
|
||||||
<< " archiveDbExists " << archiveDbExists << std::endl
|
<< " archiveDbExists " << archiveDbExists << std::endl
|
||||||
<< " writableDb '" << state.writableDb
|
<< " writableDb '" << state.writableDb
|
||||||
|
|||||||
@@ -363,6 +363,78 @@ Journal::Stream::operator<< (T const& t) const
|
|||||||
return ScopedStream (*this, t);
|
return ScopedStream (*this, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class CharT, class Traits = std::char_traits<CharT>>
|
||||||
|
class logstream_buf
|
||||||
|
: public std::basic_stringbuf<CharT, Traits>
|
||||||
|
{
|
||||||
|
beast::Journal::Stream strm_;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void write(T const*) = delete;
|
||||||
|
|
||||||
|
void write(char const* s)
|
||||||
|
{
|
||||||
|
if(strm_)
|
||||||
|
strm_ << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(wchar_t const* s)
|
||||||
|
{
|
||||||
|
if(strm_)
|
||||||
|
strm_ << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit
|
||||||
|
logstream_buf(beast::Journal::Stream const& strm)
|
||||||
|
: strm_(strm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~logstream_buf()
|
||||||
|
{
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sync() override
|
||||||
|
{
|
||||||
|
write(this->str().c_str());
|
||||||
|
this->str("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
template<
|
||||||
|
class CharT,
|
||||||
|
class Traits = std::char_traits<CharT>
|
||||||
|
>
|
||||||
|
class basic_logstream
|
||||||
|
: public std::basic_ostream<CharT, Traits>
|
||||||
|
{
|
||||||
|
typedef CharT char_type;
|
||||||
|
typedef Traits traits_type;
|
||||||
|
typedef typename traits_type::int_type int_type;
|
||||||
|
typedef typename traits_type::pos_type pos_type;
|
||||||
|
typedef typename traits_type::off_type off_type;
|
||||||
|
|
||||||
|
detail::logstream_buf<CharT, Traits> buf_;
|
||||||
|
public:
|
||||||
|
explicit
|
||||||
|
basic_logstream(beast::Journal::Stream const& strm)
|
||||||
|
: std::basic_ostream<CharT, Traits>(&buf_)
|
||||||
|
, buf_(strm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using logstream = basic_logstream<char>;
|
||||||
|
using logwstream = basic_logstream<wchar_t>;
|
||||||
|
|
||||||
} // beast
|
} // beast
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -263,6 +263,9 @@ void Config::setup (std::string const& strConf, bool bQuiet,
|
|||||||
|
|
||||||
void Config::load ()
|
void Config::load ()
|
||||||
{
|
{
|
||||||
|
// NOTE: this writes to cerr because we want cout to be reserved
|
||||||
|
// for the writing of the json response (so that stdout can be part of a
|
||||||
|
// pipeline, for instance)
|
||||||
if (!QUIET)
|
if (!QUIET)
|
||||||
std::cerr << "Loading: " << CONFIG_FILE << "\n";
|
std::cerr << "Loading: " << CONFIG_FILE << "\n";
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
std::size_t responseMax,
|
std::size_t responseMax,
|
||||||
std::chrono::seconds timeout,
|
std::chrono::seconds timeout,
|
||||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||||
Logs& l);
|
beast::Journal& j);
|
||||||
|
|
||||||
static void get (
|
static void get (
|
||||||
bool bSSL,
|
bool bSSL,
|
||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
std::size_t responseMax,
|
std::size_t responseMax,
|
||||||
std::chrono::seconds timeout,
|
std::chrono::seconds timeout,
|
||||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||||
Logs& l);
|
beast::Journal& j);
|
||||||
|
|
||||||
static void request (
|
static void request (
|
||||||
bool bSSL,
|
bool bSSL,
|
||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
std::size_t responseMax,
|
std::size_t responseMax,
|
||||||
std::chrono::seconds timeout,
|
std::chrono::seconds timeout,
|
||||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||||
Logs& l);
|
beast::Journal& j);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -105,14 +105,14 @@ public:
|
|||||||
HTTPClientImp (boost::asio::io_service& io_service,
|
HTTPClientImp (boost::asio::io_service& io_service,
|
||||||
const unsigned short port,
|
const unsigned short port,
|
||||||
std::size_t responseMax,
|
std::size_t responseMax,
|
||||||
Logs& l)
|
beast::Journal& j)
|
||||||
: mSocket (io_service, httpClientSSLContext->context ())
|
: mSocket (io_service, httpClientSSLContext->context ())
|
||||||
, mResolver (io_service)
|
, mResolver (io_service)
|
||||||
, mHeader (maxClientHeaderBytes)
|
, mHeader (maxClientHeaderBytes)
|
||||||
, mPort (port)
|
, mPort (port)
|
||||||
, mResponseMax (responseMax)
|
, mResponseMax (responseMax)
|
||||||
, mDeadline (io_service)
|
, mDeadline (io_service)
|
||||||
, j_ (l.journal ("HTTPClient"))
|
, j_ (j)
|
||||||
{
|
{
|
||||||
if (!httpClientSSLContext->sslVerify())
|
if (!httpClientSSLContext->sslVerify())
|
||||||
mSocket.SSLSocket ().set_verify_mode (boost::asio::ssl::verify_none);
|
mSocket.SSLSocket ().set_verify_mode (boost::asio::ssl::verify_none);
|
||||||
@@ -540,10 +540,10 @@ void HTTPClient::get (
|
|||||||
std::chrono::seconds timeout,
|
std::chrono::seconds timeout,
|
||||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||||
std::string const& strData)> complete,
|
std::string const& strData)> complete,
|
||||||
Logs& l)
|
beast::Journal& j)
|
||||||
{
|
{
|
||||||
auto client = std::make_shared<HTTPClientImp> (
|
auto client = std::make_shared<HTTPClientImp> (
|
||||||
io_service, port, responseMax, l);
|
io_service, port, responseMax, j);
|
||||||
client->get (bSSL, deqSites, strPath, timeout, complete);
|
client->get (bSSL, deqSites, strPath, timeout, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,12 +557,12 @@ void HTTPClient::get (
|
|||||||
std::chrono::seconds timeout,
|
std::chrono::seconds timeout,
|
||||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||||
std::string const& strData)> complete,
|
std::string const& strData)> complete,
|
||||||
Logs& l)
|
beast::Journal& j)
|
||||||
{
|
{
|
||||||
std::deque<std::string> deqSites (1, strSite);
|
std::deque<std::string> deqSites (1, strSite);
|
||||||
|
|
||||||
auto client = std::make_shared<HTTPClientImp> (
|
auto client = std::make_shared<HTTPClientImp> (
|
||||||
io_service, port, responseMax, l);
|
io_service, port, responseMax, j);
|
||||||
client->get (bSSL, deqSites, strPath, timeout, complete);
|
client->get (bSSL, deqSites, strPath, timeout, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,12 +576,12 @@ void HTTPClient::request (
|
|||||||
std::chrono::seconds timeout,
|
std::chrono::seconds timeout,
|
||||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||||
std::string const& strData)> complete,
|
std::string const& strData)> complete,
|
||||||
Logs& l)
|
beast::Journal& j)
|
||||||
{
|
{
|
||||||
std::deque<std::string> deqSites (1, strSite);
|
std::deque<std::string> deqSites (1, strSite);
|
||||||
|
|
||||||
auto client = std::make_shared<HTTPClientImp> (
|
auto client = std::make_shared<HTTPClientImp> (
|
||||||
io_service, port, responseMax, l);
|
io_service, port, responseMax, j);
|
||||||
client->request (bSSL, deqSites, setRequest, timeout, complete);
|
client->request (bSSL, deqSites, setRequest, timeout, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1297,8 +1297,9 @@ rpcClient(std::vector<std::string> const& args,
|
|||||||
ServerHandler::Setup setup;
|
ServerHandler::Setup setup;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
setup = setup_ServerHandler(
|
||||||
setup = setup_ServerHandler(config, ss);
|
config,
|
||||||
|
beast::logstream { logs.journal ("HTTPClient").warn() });
|
||||||
}
|
}
|
||||||
catch (std::exception const&)
|
catch (std::exception const&)
|
||||||
{
|
{
|
||||||
@@ -1429,10 +1430,12 @@ void fromNetwork (
|
|||||||
Logs& logs,
|
Logs& logs,
|
||||||
std::function<void (Json::Value const& jvInput)> callbackFuncP)
|
std::function<void (Json::Value const& jvInput)> callbackFuncP)
|
||||||
{
|
{
|
||||||
|
auto j = logs.journal ("HTTPClient");
|
||||||
|
|
||||||
// Connect to localhost
|
// Connect to localhost
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
{
|
{
|
||||||
std::cerr << (bSSL ? "Securely connecting to " : "Connecting to ") <<
|
JLOG(j.info()) << (bSSL ? "Securely connecting to " : "Connecting to ") <<
|
||||||
strIp << ":" << iPort << std::endl;
|
strIp << ":" << iPort << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1449,8 +1452,6 @@ void fromNetwork (
|
|||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
auto constexpr RPC_NOTIFY = 10min;
|
auto constexpr RPC_NOTIFY = 10min;
|
||||||
|
|
||||||
auto j = logs.journal ("HTTPClient");
|
|
||||||
|
|
||||||
HTTPClient::request (
|
HTTPClient::request (
|
||||||
bSSL,
|
bSSL,
|
||||||
io_service,
|
io_service,
|
||||||
@@ -1467,7 +1468,7 @@ void fromNetwork (
|
|||||||
std::bind (&RPCCallImp::onResponse, callbackFuncP,
|
std::bind (&RPCCallImp::onResponse, callbackFuncP,
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
std::placeholders::_3, j),
|
std::placeholders::_3, j),
|
||||||
logs);
|
j);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // RPCCall
|
} // RPCCall
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ using ServerHandler = ServerHandlerImp;
|
|||||||
ServerHandler::Setup
|
ServerHandler::Setup
|
||||||
setup_ServerHandler (
|
setup_ServerHandler (
|
||||||
Config const& c,
|
Config const& c,
|
||||||
std::ostream& log);
|
std::ostream&& log);
|
||||||
|
|
||||||
std::unique_ptr <ServerHandler>
|
std::unique_ptr <ServerHandler>
|
||||||
make_ServerHandler (Application& app, Stoppable& parent, boost::asio::io_service&,
|
make_ServerHandler (Application& app, Stoppable& parent, boost::asio::io_service&,
|
||||||
|
|||||||
@@ -955,7 +955,7 @@ setup_Overlay (ServerHandler::Setup& setup)
|
|||||||
ServerHandler::Setup
|
ServerHandler::Setup
|
||||||
setup_ServerHandler(
|
setup_ServerHandler(
|
||||||
Config const& config,
|
Config const& config,
|
||||||
std::ostream& log)
|
std::ostream&& log)
|
||||||
{
|
{
|
||||||
ServerHandler::Setup setup;
|
ServerHandler::Setup setup;
|
||||||
setup.ports = parse_Ports(config, log);
|
setup.ports = parse_Ports(config, log);
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public:
|
|||||||
|
|
||||||
BEAST_EXPECT(source.deepCompare (destination));
|
BEAST_EXPECT(source.deepCompare (destination));
|
||||||
|
|
||||||
std::cerr << "Checking destination invariants" << std::endl;
|
log << "Checking destination invariants..." << std::endl;
|
||||||
destination.invariants();
|
destination.invariants();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user