mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 21:15:58 +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 ());
|
||||
|
||||
{
|
||||
auto setup = setup_ServerHandler(*config_, std::cerr);
|
||||
auto setup = setup_ServerHandler(
|
||||
*config_,
|
||||
beast::logstream { m_journal.error() });
|
||||
setup.makeContexts();
|
||||
serverHandler_->setup (setup, m_journal);
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ SHAMapStoreImp::dbPaths()
|
||||
{
|
||||
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();
|
||||
Throw<std::runtime_error> (
|
||||
"node db path must be a directory.");
|
||||
@@ -494,7 +494,7 @@ SHAMapStoreImp::dbPaths()
|
||||
stateDbPathName /= dbName_;
|
||||
stateDbPathName += "*";
|
||||
|
||||
std::cerr << "state db error: " << std::endl
|
||||
journal_.error() << "state db error: " << std::endl
|
||||
<< " writableDbExists " << writableDbExists
|
||||
<< " archiveDbExists " << archiveDbExists << std::endl
|
||||
<< " writableDb '" << state.writableDb
|
||||
|
||||
@@ -363,6 +363,78 @@ Journal::Stream::operator<< (T const& t) const
|
||||
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
|
||||
|
||||
#endif
|
||||
|
||||
@@ -263,6 +263,9 @@ void Config::setup (std::string const& strConf, bool bQuiet,
|
||||
|
||||
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)
|
||||
std::cerr << "Loading: " << CONFIG_FILE << "\n";
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
std::size_t responseMax,
|
||||
std::chrono::seconds timeout,
|
||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||
Logs& l);
|
||||
beast::Journal& j);
|
||||
|
||||
static void get (
|
||||
bool bSSL,
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
std::size_t responseMax,
|
||||
std::chrono::seconds timeout,
|
||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||
Logs& l);
|
||||
beast::Journal& j);
|
||||
|
||||
static void request (
|
||||
bool bSSL,
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
std::size_t responseMax,
|
||||
std::chrono::seconds timeout,
|
||||
std::function <bool (const boost::system::error_code& ecResult, int iStatus, std::string const& strData)> complete,
|
||||
Logs& l);
|
||||
beast::Journal& j);
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -105,14 +105,14 @@ public:
|
||||
HTTPClientImp (boost::asio::io_service& io_service,
|
||||
const unsigned short port,
|
||||
std::size_t responseMax,
|
||||
Logs& l)
|
||||
beast::Journal& j)
|
||||
: mSocket (io_service, httpClientSSLContext->context ())
|
||||
, mResolver (io_service)
|
||||
, mHeader (maxClientHeaderBytes)
|
||||
, mPort (port)
|
||||
, mResponseMax (responseMax)
|
||||
, mDeadline (io_service)
|
||||
, j_ (l.journal ("HTTPClient"))
|
||||
, j_ (j)
|
||||
{
|
||||
if (!httpClientSSLContext->sslVerify())
|
||||
mSocket.SSLSocket ().set_verify_mode (boost::asio::ssl::verify_none);
|
||||
@@ -540,10 +540,10 @@ void HTTPClient::get (
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete,
|
||||
Logs& l)
|
||||
beast::Journal& j)
|
||||
{
|
||||
auto client = std::make_shared<HTTPClientImp> (
|
||||
io_service, port, responseMax, l);
|
||||
io_service, port, responseMax, j);
|
||||
client->get (bSSL, deqSites, strPath, timeout, complete);
|
||||
}
|
||||
|
||||
@@ -557,12 +557,12 @@ void HTTPClient::get (
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete,
|
||||
Logs& l)
|
||||
beast::Journal& j)
|
||||
{
|
||||
std::deque<std::string> deqSites (1, strSite);
|
||||
|
||||
auto client = std::make_shared<HTTPClientImp> (
|
||||
io_service, port, responseMax, l);
|
||||
io_service, port, responseMax, j);
|
||||
client->get (bSSL, deqSites, strPath, timeout, complete);
|
||||
}
|
||||
|
||||
@@ -576,12 +576,12 @@ void HTTPClient::request (
|
||||
std::chrono::seconds timeout,
|
||||
std::function<bool (const boost::system::error_code& ecResult, int iStatus,
|
||||
std::string const& strData)> complete,
|
||||
Logs& l)
|
||||
beast::Journal& j)
|
||||
{
|
||||
std::deque<std::string> deqSites (1, strSite);
|
||||
|
||||
auto client = std::make_shared<HTTPClientImp> (
|
||||
io_service, port, responseMax, l);
|
||||
io_service, port, responseMax, j);
|
||||
client->request (bSSL, deqSites, setRequest, timeout, complete);
|
||||
}
|
||||
|
||||
|
||||
@@ -1297,8 +1297,9 @@ rpcClient(std::vector<std::string> const& args,
|
||||
ServerHandler::Setup setup;
|
||||
try
|
||||
{
|
||||
std::stringstream ss;
|
||||
setup = setup_ServerHandler(config, ss);
|
||||
setup = setup_ServerHandler(
|
||||
config,
|
||||
beast::logstream { logs.journal ("HTTPClient").warn() });
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
@@ -1429,10 +1430,12 @@ void fromNetwork (
|
||||
Logs& logs,
|
||||
std::function<void (Json::Value const& jvInput)> callbackFuncP)
|
||||
{
|
||||
auto j = logs.journal ("HTTPClient");
|
||||
|
||||
// Connect to localhost
|
||||
if (!quiet)
|
||||
{
|
||||
std::cerr << (bSSL ? "Securely connecting to " : "Connecting to ") <<
|
||||
JLOG(j.info()) << (bSSL ? "Securely connecting to " : "Connecting to ") <<
|
||||
strIp << ":" << iPort << std::endl;
|
||||
}
|
||||
|
||||
@@ -1449,8 +1452,6 @@ void fromNetwork (
|
||||
using namespace std::chrono_literals;
|
||||
auto constexpr RPC_NOTIFY = 10min;
|
||||
|
||||
auto j = logs.journal ("HTTPClient");
|
||||
|
||||
HTTPClient::request (
|
||||
bSSL,
|
||||
io_service,
|
||||
@@ -1467,7 +1468,7 @@ void fromNetwork (
|
||||
std::bind (&RPCCallImp::onResponse, callbackFuncP,
|
||||
std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, j),
|
||||
logs);
|
||||
j);
|
||||
}
|
||||
|
||||
} // RPCCall
|
||||
|
||||
@@ -40,7 +40,7 @@ using ServerHandler = ServerHandlerImp;
|
||||
ServerHandler::Setup
|
||||
setup_ServerHandler (
|
||||
Config const& c,
|
||||
std::ostream& log);
|
||||
std::ostream&& log);
|
||||
|
||||
std::unique_ptr <ServerHandler>
|
||||
make_ServerHandler (Application& app, Stoppable& parent, boost::asio::io_service&,
|
||||
|
||||
@@ -955,7 +955,7 @@ setup_Overlay (ServerHandler::Setup& setup)
|
||||
ServerHandler::Setup
|
||||
setup_ServerHandler(
|
||||
Config const& config,
|
||||
std::ostream& log)
|
||||
std::ostream&& log)
|
||||
{
|
||||
ServerHandler::Setup setup;
|
||||
setup.ports = parse_Ports(config, log);
|
||||
|
||||
@@ -194,7 +194,7 @@ public:
|
||||
|
||||
BEAST_EXPECT(source.deepCompare (destination));
|
||||
|
||||
std::cerr << "Checking destination invariants" << std::endl;
|
||||
log << "Checking destination invariants..." << std::endl;
|
||||
destination.invariants();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user