Simplify logging:

* Construct Logs with the correct severity
* Remove deprecatedLogs and log squelching support
* Use debugJournal for AutoSocket logging
This commit is contained in:
Nik Bougalis
2016-02-16 16:21:54 -08:00
committed by seelabs
parent 6366f62f11
commit bf6079797f
14 changed files with 29 additions and 135 deletions

View File

@@ -3759,9 +3759,6 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\websocket\Handler.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\websocket\LogWebsockets.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\websocket\MakeServer.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>

View File

@@ -4239,9 +4239,6 @@
<ClInclude Include="..\..\src\ripple\websocket\Handler.h">
<Filter>ripple\websocket</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\websocket\LogWebsockets.cpp">
<Filter>ripple\websocket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\websocket\MakeServer.cpp">
<Filter>ripple\websocket</Filter>
</ClCompile>

View File

@@ -419,18 +419,19 @@ int run (int argc, char** argv)
}
}
// Construct the logs object at the configured severity
beast::Journal::Severity thresh = beast::Journal::kInfo;
if (vm.count ("quiet"))
thresh = beast::Journal::kFatal;
else if (vm.count ("verbose"))
thresh = beast::Journal::kTrace;
auto logs = std::make_unique<Logs>(thresh);
// No arguments. Run server.
if (!vm.count ("parameters"))
{
auto logs = std::make_unique<Logs>();
if (vm.count ("quiet"))
logs->threshold (beast::Journal::kFatal);
else if (vm.count ("verbose"))
logs->threshold (beast::Journal::kTrace);
else
logs->threshold (beast::Journal::kInfo);
if (vm.count ("debug"))
setDebugJournalSink (logs->get("Debug"));
@@ -450,7 +451,8 @@ int run (int argc, char** argv)
setCallingThreadName ("rpc");
return RPCCall::fromCommandLine (
*config,
vm["parameters"].as<std::vector<std::string>>(), deprecatedLogs());
vm["parameters"].as<std::vector<std::string>>(),
*logs);
}
extern int run (int argc, char** argv);

View File

@@ -154,7 +154,7 @@ private:
bool silent_ = false;
public:
Logs();
Logs(beast::Journal::Severity level);
Logs (Logs const&) = delete;
Logs& operator= (Logs const&) = delete;
@@ -262,35 +262,6 @@ debugJournal();
void
setDebugJournalSink(beast::Journal::Sink& sink);
//------------------------------------------------------------------------------
// VFALCO DEPRECATED Temporary transition function until interfaces injected
inline
Logs&
deprecatedLogs()
{
static Logs logs;
return logs;
}
class LogSquelcher
{
public:
LogSquelcher()
: thresh_(deprecatedLogs().threshold())
{
deprecatedLogs().threshold(
beast::Journal::Severity::kNone);
}
~LogSquelcher()
{
deprecatedLogs().threshold(thresh_);
}
private:
beast::Journal::Severity const thresh_;
};
} // ripple
#endif

View File

@@ -111,8 +111,8 @@ void Logs::File::writeln (char const* text)
//------------------------------------------------------------------------------
Logs::Logs()
: thresh_ (beast::Journal::kWarning) // default severity
Logs::Logs(beast::Journal::Severity thresh)
: thresh_ (thresh) // default severity
{
}

View File

@@ -104,7 +104,6 @@ class SkipList_test : public beast::unit_test::suite
void run()
{
LogSquelcher l;
testSkipList();
}
};

View File

@@ -106,7 +106,7 @@ public:
const unsigned short port,
std::size_t responseMax,
Logs& l)
: mSocket (io_service, httpClientSSLContext->context (), l.journal ("AutoSocket"))
: mSocket (io_service, httpClientSSLContext->context ())
, mResolver (io_service)
, mHeader (maxClientHeaderBytes)
, mPort (port)

View File

@@ -406,7 +406,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
app.logs(),
&rcInput);
JLOG(j.warning)
JLOG(j.info)
<< "ripple_path_find:"
<< " saMaxAmount=" << saMaxAmount
<< " saDstAmount=" << saDstAmount

View File

@@ -109,7 +109,6 @@ private:
};
AppBundle bundle_;
LogSquelcher logSquelcher_;
inline
void

View File

@@ -135,7 +135,8 @@ class SuiteLogs : public Logs
public:
explicit
SuiteLogs(beast::unit_test::suite& suite)
: suite_(suite)
: Logs (beast::Journal::kError)
, suite_(suite)
{
}

View File

@@ -41,7 +41,6 @@
#include <ripple/websocket/WebSocket02.cpp>
#include <ripple/websocket/MakeServer.cpp>
#include <ripple/websocket/LogWebsockets.cpp>
// Must come last to prevent compilation errors.
#include <websocketpp_02/src/md5/md5.c>

View File

@@ -46,31 +46,24 @@ public:
using callback = std::function <void (error_code)>;
public:
AutoSocket (boost::asio::io_service& s, boost::asio::ssl::context& c, beast::Journal j)
: mSecure (false)
, mBuffer (4)
, j_ (j)
{
mSocket = std::make_shared<ssl_socket> (s, c);
}
AutoSocket (
boost::asio::io_service& s, boost::asio::ssl::context& c,
bool secureOnly, bool plainOnly, beast::Journal j)
boost::asio::io_service& s,
boost::asio::ssl::context& c,
bool secureOnly,
bool plainOnly)
: mSecure (secureOnly)
, mBuffer ((plainOnly || secureOnly) ? 0 : 4)
, j_ (j)
, j_ (ripple::debugJournal())
{
mSocket = std::make_shared<ssl_socket> (s, c);
}
// swd TBD try remove this constructor
// This needs to use `deprecatedLogs` or a change is needed
// in websocket_02 (which breaks leveling)
AutoSocket (
boost::asio::io_service& s, boost::asio::ssl::context& c,
bool secureOnly, bool plainOnly)
: AutoSocket (s, c, secureOnly, plainOnly, ripple::deprecatedLogs().journal ("AutoSocket")){}
boost::asio::io_service& s,
boost::asio::ssl::context& c)
: AutoSocket (s, c, false, false)
{
}
boost::asio::io_service& get_io_service () noexcept
{

View File

@@ -1,61 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
// VFALCO NOTE this looks like some facility for giving websocket
// a way to produce logging output.
//
namespace websocketpp_02 {
namespace log {
void websocketLog (
websocketpp_02::log::alevel::value v, std::string const& entry)
{
auto const isTrace =
v == websocketpp_02::log::alevel::DEVEL ||
v == websocketpp_02::log::alevel::DEBUG_CLOSE;
auto journal = ripple::debugJournal();
if (isTrace)
JLOG (journal.trace) << entry;
else
JLOG (journal.debug) << entry;
}
void websocketLog (
websocketpp_02::log::elevel::value v, std::string const& entry)
{
auto journal = ripple::debugJournal();
if ((v & websocketpp_02::log::elevel::INFO) != 0)
JLOG (journal.info) << entry;
else if ((v & websocketpp_02::log::elevel::FATAL) != 0)
JLOG (journal.fatal) << entry;
else if ((v & websocketpp_02::log::elevel::RERROR) != 0)
JLOG (journal.error) << entry;
else if ((v & websocketpp_02::log::elevel::WARN) != 0)
JLOG (journal.warning) << entry;
else
JLOG (journal.debug) << entry;
}
}
}
// vim:ts=4

View File

@@ -85,9 +85,6 @@ namespace elevel {
static const value ALL = 0xFFFF;
}
extern void websocketLog(alevel::value, const std::string&);
extern void websocketLog(elevel::value, const std::string&);
template <typename level_type>
class logger {
public: