diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 13df3b09ff..6976233a1e 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -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); } diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index 76ad533f3b..758466027b 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -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 ( "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 diff --git a/src/ripple/beast/utility/Journal.h b/src/ripple/beast/utility/Journal.h index 123bd7e3a6..460b160a43 100644 --- a/src/ripple/beast/utility/Journal.h +++ b/src/ripple/beast/utility/Journal.h @@ -363,6 +363,78 @@ Journal::Stream::operator<< (T const& t) const return ScopedStream (*this, t); } +namespace detail { + +template> +class logstream_buf + : public std::basic_stringbuf +{ + beast::Journal::Stream strm_; + + template + 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 +> +class basic_logstream + : public std::basic_ostream +{ + 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 buf_; +public: + explicit + basic_logstream(beast::Journal::Stream const& strm) + : std::basic_ostream(&buf_) + , buf_(strm) + { + } +}; + +using logstream = basic_logstream; +using logwstream = basic_logstream; + } // beast #endif diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index bc95f824e3..491231c90e 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -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"; diff --git a/src/ripple/net/HTTPClient.h b/src/ripple/net/HTTPClient.h index 5ce74f5a74..634397eb77 100644 --- a/src/ripple/net/HTTPClient.h +++ b/src/ripple/net/HTTPClient.h @@ -48,7 +48,7 @@ public: std::size_t responseMax, std::chrono::seconds timeout, std::function 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 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 complete, - Logs& l); + beast::Journal& j); }; } // ripple diff --git a/src/ripple/net/impl/HTTPClient.cpp b/src/ripple/net/impl/HTTPClient.cpp index cbbc0213e6..dcad22e958 100644 --- a/src/ripple/net/impl/HTTPClient.cpp +++ b/src/ripple/net/impl/HTTPClient.cpp @@ -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 complete, - Logs& l) + beast::Journal& j) { auto client = std::make_shared ( - 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 complete, - Logs& l) + beast::Journal& j) { std::deque deqSites (1, strSite); auto client = std::make_shared ( - 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 complete, - Logs& l) + beast::Journal& j) { std::deque deqSites (1, strSite); auto client = std::make_shared ( - io_service, port, responseMax, l); + io_service, port, responseMax, j); client->request (bSSL, deqSites, setRequest, timeout, complete); } diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 8b3455664f..6f300c094f 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -1297,8 +1297,9 @@ rpcClient(std::vector 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 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 diff --git a/src/ripple/rpc/ServerHandler.h b/src/ripple/rpc/ServerHandler.h index 190205c682..5750ebcca7 100644 --- a/src/ripple/rpc/ServerHandler.h +++ b/src/ripple/rpc/ServerHandler.h @@ -40,7 +40,7 @@ using ServerHandler = ServerHandlerImp; ServerHandler::Setup setup_ServerHandler ( Config const& c, - std::ostream& log); + std::ostream&& log); std::unique_ptr make_ServerHandler (Application& app, Stoppable& parent, boost::asio::io_service&, diff --git a/src/ripple/rpc/impl/ServerHandlerImp.cpp b/src/ripple/rpc/impl/ServerHandlerImp.cpp index f6af81f6f7..984607c302 100644 --- a/src/ripple/rpc/impl/ServerHandlerImp.cpp +++ b/src/ripple/rpc/impl/ServerHandlerImp.cpp @@ -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); diff --git a/src/test/shamap/SHAMapSync_test.cpp b/src/test/shamap/SHAMapSync_test.cpp index ced902fcd8..fead368073 100644 --- a/src/test/shamap/SHAMapSync_test.cpp +++ b/src/test/shamap/SHAMapSync_test.cpp @@ -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(); } };