diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj
index 9698689f80..7f2e499ecd 100644
--- a/Builds/VisualStudio2015/RippleD.vcxproj
+++ b/Builds/VisualStudio2015/RippleD.vcxproj
@@ -2548,8 +2548,6 @@
-
-
diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters
index 7253393820..72439a7394 100644
--- a/Builds/VisualStudio2015/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters
@@ -3096,9 +3096,6 @@
ripple\peerfinder\sim
-
- ripple\peerfinder\sim
-
ripple\peerfinder
diff --git a/src/beast/beast/utility/Journal.h b/src/beast/beast/utility/Journal.h
index 3b4171f36b..6e6cca587a 100644
--- a/src/beast/beast/utility/Journal.h
+++ b/src/beast/beast/utility/Journal.h
@@ -24,7 +24,18 @@
namespace beast {
-/** A generic endpoint for log messages. */
+/** A generic endpoint for log messages.
+
+ The Journal has a few simple goals:
+
+ * To be light-weight and copied by value.
+ * To allow logging statements to be left in source code.
+ * The logging is controlled at run-time based on a logging threshold.
+
+ It is advisable to check Journal::active(level) prior to formatting log
+ text. Doing so sidesteps expensive text formatting when the results
+ will not be sent to the log.
+*/
class Journal
{
public:
@@ -47,10 +58,7 @@ public:
class Sink;
private:
- Journal& operator= (Journal const& other); // disallowed
-
Sink* m_sink;
- Severity m_level;
public:
//--------------------------------------------------------------------------
@@ -58,9 +66,12 @@ public:
/** Abstraction for the underlying message destination. */
class Sink
{
- public:
- Sink ();
+ protected:
+ Sink () = delete;
+ explicit Sink(Sink const& sink) = default;
+ Sink (Severity thresh, bool console);
+ public:
virtual ~Sink () = 0;
/** Returns `true` if text at the passed severity produces output. */
@@ -73,19 +84,19 @@ public:
virtual void console (bool output);
/** Returns the minimum severity level this sink will report. */
- virtual Severity severity() const;
+ virtual Severity threshold() const;
/** Set the minimum severity this sink will report. */
- virtual void severity (Severity level);
+ virtual void threshold (Severity thresh);
/** Write text to the sink at the specified severity.
- The caller is responsible for checking the minimum severity level
- before using this function.
+ A conforming implementation will not write the text if the passed
+ level is below the current threshold().
*/
virtual void write (Severity level, std::string const& text) = 0;
private:
- Severity m_level;
+ Severity thresh_;
bool m_console;
};
@@ -107,10 +118,8 @@ public:
ScopedStream (Stream const& stream, T const& t)
: m_sink (stream.sink())
, m_level (stream.severity())
- , m_active (stream.active ())
{
- if (active ())
- m_ostream << t;
+ m_ostream << t;
}
ScopedStream (Stream const& stream,
@@ -118,9 +127,6 @@ public:
~ScopedStream ();
- bool active () const
- { return m_active; }
-
std::ostringstream& ostream () const;
std::ostream& operator<< (
@@ -129,8 +135,7 @@ public:
template
std::ostream& operator<< (T const& t) const
{
- if (active ())
- m_ostream << t;
+ m_ostream << t;
return m_ostream;
}
@@ -140,10 +145,8 @@ public:
ScopedStream& operator= (ScopedStream const&); // disallowed
Sink& m_sink;
- Severity const m_level;
- bool const m_active;
+ Severity const m_level; // cached from Stream for call to m_sink.write
std::ostringstream mutable m_ostream;
- bool m_toOutputWindow;
};
//--------------------------------------------------------------------------
@@ -155,10 +158,7 @@ public:
Stream ();
/** Create stream that writes at the given level. */
- /** @{ */
- Stream (Sink& sink, Severity level, bool active = true);
- Stream (Stream const& stream, bool active);
- /** @} */
+ Stream (Sink& sink, Severity level);
/** Construct or copy another Stream. */
/** @{ */
@@ -174,7 +174,10 @@ public:
/** Returns `true` if sink logs anything at this stream's severity. */
/** @{ */
- bool active() const;
+ bool active() const
+ {
+ return m_sink->active (m_level);
+ }
explicit
operator bool() const
@@ -197,7 +200,6 @@ public:
private:
Sink* m_sink;
Severity m_level;
- bool m_disabled;
};
//--------------------------------------------------------------------------
@@ -206,17 +208,13 @@ public:
Journal ();
/** Create a journal that writes to the specified sink. */
- /** @{ */
- explicit Journal (Sink& sink, Severity level = kAll);
+ explicit Journal (Sink& sink);
- /** Create a journal from another journal.
- When specifying a new minimum severity level, the effective minimum
- level will be the higher of the other journal and the specified value.
- */
- /** @{ */
+ /** Create a journal from another journal. */
Journal (Journal const& other);
- Journal (Journal const& other, Severity level);
- /** @} */
+
+ // Disallowed.
+ Journal& operator= (Journal const& other) = delete;
/** Destroy the journal. */
~Journal ();
@@ -228,17 +226,11 @@ public:
Stream stream (Severity level) const;
/** Returns `true` if any message would be logged at this severity level.
- For a message to be logged, the severity must be at or above both
- the journal's severity level and the sink's severity level.
+ For a message to be logged, the severity must be at or above the
+ sink's severity threshold.
*/
bool active (Severity level) const;
- /** Returns this Journal's minimum severity level.
- If the underlying sink has a higher threshold, there will still
- be no output at that level.
- */
- Severity severity () const;
-
/** Convenience sink streams for each severity level. */
Stream const trace;
Stream const debug;
diff --git a/src/beast/beast/utility/WrappedSink.h b/src/beast/beast/utility/WrappedSink.h
index 672812b9c1..010670211f 100644
--- a/src/beast/beast/utility/WrappedSink.h
+++ b/src/beast/beast/utility/WrappedSink.h
@@ -25,6 +25,11 @@
namespace beast {
/** Wraps a Journal::Sink to prefix its output with a string. */
+
+// A WrappedSink both is a Sink and has a Sink:
+// o It inherits from Sink so it has the correct interface.
+// o It has a sink (reference) so it preserves the passed write() behavior.
+// The data inherited from the base class is ignored.
class WrappedSink : public beast::Journal::Sink
{
private:
@@ -34,15 +39,15 @@ private:
public:
explicit
WrappedSink (beast::Journal::Sink& sink, std::string const& prefix = "")
- : sink_(sink)
+ : Sink (sink)
+ , sink_(sink)
, prefix_(prefix)
{
}
explicit
WrappedSink (beast::Journal const& journal, std::string const& prefix = "")
- : sink_(journal.sink())
- , prefix_(prefix)
+ : WrappedSink (journal.sink(), prefix)
{
}
@@ -69,14 +74,14 @@ public:
}
beast::Journal::Severity
- severity() const override
+ threshold() const override
{
- return sink_.severity();
+ return sink_.threshold();
}
- void severity (beast::Journal::Severity level) override
+ void threshold (beast::Journal::Severity thresh) override
{
- sink_.severity (level);
+ sink_.threshold (thresh);
}
void write (beast::Journal::Severity level, std::string const& text) override
diff --git a/src/beast/beast/utility/impl/Journal.cpp b/src/beast/beast/utility/impl/Journal.cpp
index 92064aa1af..5b92839793 100644
--- a/src/beast/beast/utility/impl/Journal.cpp
+++ b/src/beast/beast/utility/impl/Journal.cpp
@@ -28,30 +28,36 @@ namespace beast {
class NullJournalSink : public Journal::Sink
{
public:
- bool active (Journal::Severity) const
+ NullJournalSink ()
+ : Sink (Journal::kDisabled, false)
+ { }
+
+ ~NullJournalSink() override = default;
+
+ bool active (Journal::Severity) const override
{
return false;
}
- bool console() const
+ bool console() const override
{
return false;
}
- void console (bool)
+ void console (bool) override
{
}
- Journal::Severity severity() const
+ Journal::Severity threshold() const override
{
return Journal::kDisabled;
}
- void severity (Journal::Severity)
+ void threshold (Journal::Severity) override
{
}
- void write (Journal::Severity, std::string const&)
+ void write (Journal::Severity, std::string const&) override
{
}
};
@@ -66,9 +72,9 @@ Journal::Sink& Journal::getNullSink ()
//------------------------------------------------------------------------------
-Journal::Sink::Sink ()
- : m_level (kWarning)
- , m_console (false)
+Journal::Sink::Sink (Severity thresh, bool console)
+ : thresh_ (thresh)
+ , m_console (console)
{
}
@@ -78,7 +84,7 @@ Journal::Sink::~Sink ()
bool Journal::Sink::active (Severity level) const
{
- return level >= m_level;
+ return level >= thresh_;
}
bool Journal::Sink::console () const
@@ -91,14 +97,14 @@ void Journal::Sink::console (bool output)
m_console = output;
}
-Journal::Severity Journal::Sink::severity () const
+Journal::Severity Journal::Sink::threshold () const
{
- return m_level;
+ return thresh_;
}
-void Journal::Sink::severity (Severity level)
+void Journal::Sink::threshold (Severity thresh)
{
- m_level = level;
+ thresh_ = thresh;
}
//------------------------------------------------------------------------------
@@ -106,7 +112,6 @@ void Journal::Sink::severity (Severity level)
Journal::ScopedStream::ScopedStream (Stream const& stream)
: m_sink (stream.sink ())
, m_level (stream.severity ())
- , m_active (stream.active ())
{
init ();
}
@@ -114,7 +119,6 @@ Journal::ScopedStream::ScopedStream (Stream const& stream)
Journal::ScopedStream::ScopedStream (ScopedStream const& other)
: m_sink (other.m_sink)
, m_level (other.m_level)
- , m_active (other.m_active)
{
init ();
}
@@ -123,25 +127,20 @@ Journal::ScopedStream::ScopedStream (
Stream const& stream, std::ostream& manip (std::ostream&))
: m_sink (stream.sink ())
, m_level (stream.severity ())
- , m_active (stream.active ())
{
init ();
- if (active ())
- m_ostream << manip;
+ m_ostream << manip;
}
Journal::ScopedStream::~ScopedStream ()
{
- if (active ())
+ std::string const& s (m_ostream.str());
+ if (! s.empty ())
{
- std::string const& s (m_ostream.str());
- if (! s.empty ())
- {
- if (s == "\n")
- m_sink.write (m_level, "");
- else
- m_sink.write (m_level, s);
- }
+ if (s == "\n")
+ m_sink.write (m_level, "");
+ else
+ m_sink.write (m_level, s);
}
}
@@ -150,10 +149,7 @@ void Journal::ScopedStream::init ()
// Modifiers applied from all ctors
m_ostream
<< std::boolalpha
- << std::showbase
- //<< std::hex
- ;
-
+ << std::showbase;
}
std::ostream& Journal::ScopedStream::operator<< (std::ostream& manip (std::ostream&)) const
@@ -171,29 +167,19 @@ std::ostringstream& Journal::ScopedStream::ostream () const
Journal::Stream::Stream ()
: m_sink (&getNullSink ())
, m_level (kDisabled)
- , m_disabled (true)
{
}
-Journal::Stream::Stream (Sink& sink, Severity level, bool active)
+Journal::Stream::Stream (Sink& sink, Severity level)
: m_sink (&sink)
, m_level (level)
- , m_disabled (! active)
{
assert (level != kDisabled);
}
-Journal::Stream::Stream (Stream const& stream, bool active)
- : m_sink (&stream.sink ())
- , m_level (stream.severity ())
- , m_disabled (! active)
-{
-}
-
Journal::Stream::Stream (Stream const& other)
: m_sink (other.m_sink)
, m_level (other.m_level)
- , m_disabled (other.m_disabled)
{
}
@@ -207,11 +193,6 @@ Journal::Severity Journal::Stream::severity () const
return m_level;
}
-bool Journal::Stream::active () const
-{
- return ! m_disabled && m_sink->active (m_level);
-}
-
Journal::Stream& Journal::Stream::operator= (Stream const& other)
{
m_sink = other.m_sink;
@@ -229,7 +210,6 @@ Journal::ScopedStream Journal::Stream::operator<< (
Journal::Journal ()
: m_sink (&getNullSink())
- , m_level (kDisabled)
, trace (stream (kTrace))
, debug (stream (kDebug))
, info (stream (kInfo))
@@ -239,9 +219,8 @@ Journal::Journal ()
{
}
-Journal::Journal (Sink& sink, Severity level)
+Journal::Journal (Sink& sink)
: m_sink (&sink)
- , m_level (level)
, trace (stream (kTrace))
, debug (stream (kDebug))
, info (stream (kInfo))
@@ -252,26 +231,7 @@ Journal::Journal (Sink& sink, Severity level)
}
Journal::Journal (Journal const& other)
- : m_sink (other.m_sink)
- , m_level (other.m_level)
- , trace (stream (kTrace))
- , debug (stream (kDebug))
- , info (stream (kInfo))
- , warning (stream (kWarning))
- , error (stream (kError))
- , fatal (stream (kFatal))
-{
-}
-
-Journal::Journal (Journal const& other, Severity level)
- : m_sink (other.m_sink)
- , m_level (std::max (other.m_level, level))
- , trace (stream (kTrace))
- , debug (stream (kDebug))
- , info (stream (kInfo))
- , warning (stream (kWarning))
- , error (stream (kError))
- , fatal (stream (kFatal))
+ : Journal (*other.m_sink)
{
}
@@ -286,21 +246,12 @@ Journal::Sink& Journal::sink() const
Journal::Stream Journal::stream (Severity level) const
{
- return Stream (*m_sink, level, level >= m_level);
+ return Stream (*m_sink, level);
}
bool Journal::active (Severity level) const
{
- if (level == kDisabled)
- return false;
- if (level < m_level)
- return false;
return m_sink->active (level);
}
-Journal::Severity Journal::severity () const
-{
- return m_level;
-}
-
}
diff --git a/src/beast/beast/utility/tests/Journal.test.cpp b/src/beast/beast/utility/tests/Journal.test.cpp
index 78d510c7fe..786771d33c 100644
--- a/src/beast/beast/utility/tests/Journal.test.cpp
+++ b/src/beast/beast/utility/tests/Journal.test.cpp
@@ -32,7 +32,8 @@ public:
public:
TestSink()
- : m_count(0)
+ : Sink (Journal::kWarning, false)
+ , m_count(0)
{
}
@@ -49,9 +50,10 @@ public:
}
void
- write (Journal::Severity, std::string const&)
+ write (Journal::Severity level, std::string const&) override
{
- ++m_count;
+ if (level >= threshold())
+ ++m_count;
}
};
@@ -59,7 +61,7 @@ public:
{
TestSink sink;
- sink.severity(Journal::kInfo);
+ sink.threshold(Journal::kInfo);
Journal j(sink);
@@ -78,7 +80,7 @@ public:
sink.reset();
- sink.severity(Journal::kDebug);
+ sink.threshold(Journal::kDebug);
j.trace << " ";
expect(sink.count() == 0);
diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp
index a318377272..d68cdb278d 100644
--- a/src/ripple/app/main/Application.cpp
+++ b/src/ripple/app/main/Application.cpp
@@ -958,8 +958,8 @@ void ApplicationImp::setup()
if (!logs_->open(debug_log))
std::cerr << "Can't open log file " << debug_log << '\n';
- if (logs_->severity() > beast::Journal::kDebug)
- logs_->severity (beast::Journal::kDebug);
+ if (logs_->threshold() > beast::Journal::kDebug)
+ logs_->threshold (beast::Journal::kDebug);
}
logs_->silent (config_->SILENT);
diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp
index 877b1479f2..6c64c2baa9 100644
--- a/src/ripple/app/main/Main.cpp
+++ b/src/ripple/app/main/Main.cpp
@@ -425,11 +425,11 @@ int run (int argc, char** argv)
auto logs = std::make_unique();
if (vm.count ("quiet"))
- logs->severity (beast::Journal::kFatal);
+ logs->threshold (beast::Journal::kFatal);
else if (vm.count ("verbose"))
- logs->severity (beast::Journal::kTrace);
+ logs->threshold (beast::Journal::kTrace);
else
- logs->severity (beast::Journal::kInfo);
+ logs->threshold (beast::Journal::kInfo);
if (vm.count ("debug"))
setDebugJournalSink (logs->get("Debug"));
diff --git a/src/ripple/basics/Log.h b/src/ripple/basics/Log.h
index f52537456d..0a5a7d34e1 100644
--- a/src/ripple/basics/Log.h
+++ b/src/ripple/basics/Log.h
@@ -57,7 +57,7 @@ private:
public:
Sink (std::string const& partition,
- beast::Journal::Severity severity, Logs& logs);
+ beast::Journal::Severity thresh, Logs& logs);
Sink (Sink const&) = delete;
Sink& operator= (Sink const&) = delete;
@@ -149,7 +149,7 @@ private:
std::map ,
beast::ci_less> sinks_;
- beast::Journal::Severity level_;
+ beast::Journal::Severity thresh_;
File file_;
bool silent_ = false;
@@ -174,10 +174,10 @@ public:
journal (std::string const& name);
beast::Journal::Severity
- severity() const;
+ threshold() const;
void
- severity (beast::Journal::Severity level);
+ threshold (beast::Journal::Severity thresh);
std::vector>
partition_severities() const;
@@ -276,19 +276,19 @@ class LogSquelcher
{
public:
LogSquelcher()
- : severity_(deprecatedLogs().severity())
+ : thresh_(deprecatedLogs().threshold())
{
- deprecatedLogs().severity(
+ deprecatedLogs().threshold(
beast::Journal::Severity::kNone);
}
~LogSquelcher()
{
- deprecatedLogs().severity(severity_);
+ deprecatedLogs().threshold(thresh_);
}
private:
- beast::Journal::Severity const severity_;
+ beast::Journal::Severity const thresh_;
};
} // ripple
diff --git a/src/ripple/basics/impl/Log.cpp b/src/ripple/basics/impl/Log.cpp
index 9f84ad348d..fd6252c595 100644
--- a/src/ripple/basics/impl/Log.cpp
+++ b/src/ripple/basics/impl/Log.cpp
@@ -28,16 +28,19 @@
namespace ripple {
Logs::Sink::Sink (std::string const& partition,
- beast::Journal::Severity severity, Logs& logs)
- : logs_(logs)
+ beast::Journal::Severity thresh, Logs& logs)
+ : beast::Journal::Sink (thresh, false)
+ , logs_(logs)
, partition_(partition)
{
- beast::Journal::Sink::severity (severity);
}
void
Logs::Sink::write (beast::Journal::Severity level, std::string const& text)
{
+ if (level < threshold())
+ return;
+
logs_.write (level, partition_, text, console());
}
@@ -109,7 +112,7 @@ void Logs::File::writeln (char const* text)
//------------------------------------------------------------------------------
Logs::Logs()
- : level_ (beast::Journal::kWarning) // default severity
+ : thresh_ (beast::Journal::kWarning) // default severity
{
}
@@ -124,7 +127,7 @@ Logs::get (std::string const& name)
{
std::lock_guard lock (mutex_);
auto const result =
- sinks_.emplace(name, makeSink(name, level_));
+ sinks_.emplace(name, makeSink(name, thresh_));
return *result.first->second;
}
@@ -141,18 +144,18 @@ Logs::journal (std::string const& name)
}
beast::Journal::Severity
-Logs::severity() const
+Logs::threshold() const
{
- return level_;
+ return thresh_;
}
void
-Logs::severity (beast::Journal::Severity level)
+Logs::threshold (beast::Journal::Severity thresh)
{
std::lock_guard lock (mutex_);
- level_ = level;
+ thresh_ = thresh;
for (auto& sink : sinks_)
- sink.second->severity (level);
+ sink.second->threshold (thresh);
}
std::vector>
@@ -163,7 +166,7 @@ Logs::partition_severities() const
list.reserve (sinks_.size());
for (auto const& e : sinks_)
list.push_back(std::make_pair(e.first,
- toString(fromSeverity(e.second->severity()))));
+ toString(fromSeverity(e.second->threshold()))));
return list;
}
@@ -194,10 +197,10 @@ Logs::rotate()
std::unique_ptr
Logs::makeSink(std::string const& name,
- beast::Journal::Severity startingLevel)
+ beast::Journal::Severity threshold)
{
return std::make_unique(
- name, startingLevel, *this);
+ name, threshold, *this);
}
LogSeverity
diff --git a/src/ripple/peerfinder/impl/Logic.h b/src/ripple/peerfinder/impl/Logic.h
index e760fcf073..6e6d0c22fe 100644
--- a/src/ripple/peerfinder/impl/Logic.h
+++ b/src/ripple/peerfinder/impl/Logic.h
@@ -107,14 +107,12 @@ public:
Logic (clock_type& clock, Store& store,
Checker& checker, beast::Journal journal)
- : m_journal (journal, Reporting::logic)
+ : m_journal (journal)
, m_clock (clock)
, m_store (store)
, m_checker (checker)
- , livecache_ (m_clock,
- beast::Journal (journal, Reporting::livecache))
- , bootcache_ (store, m_clock,
- beast::Journal (journal, Reporting::bootcache))
+ , livecache_ (m_clock, journal)
+ , bootcache_ (store, m_clock, journal)
, m_whenBroadcast (m_clock.now())
, m_squelches (m_clock)
{
diff --git a/src/ripple/peerfinder/impl/Reporting.h b/src/ripple/peerfinder/impl/Reporting.h
index c11b891ae7..5efb8bc4a2 100644
--- a/src/ripple/peerfinder/impl/Reporting.h
+++ b/src/ripple/peerfinder/impl/Reporting.h
@@ -39,29 +39,6 @@ struct Reporting
// Report nodes detailed information
static bool const dump_nodes = false;
-
- //
- //
- //
-
- // Reports from Network (and children)
- static beast::Journal::Severity const network = beast::Journal::kWarning;
-
- // Reports from simulation Node (and children)
- static beast::Journal::Severity const node = beast::Journal::kAll;
-
- //
- //
- //
-
- // Reports from Logic
- static beast::Journal::Severity const logic = beast::Journal::kAll;
-
- // Reports from Livecache
- static beast::Journal::Severity const livecache = beast::Journal::kAll;
-
- // Reports from Bootcache
- static beast::Journal::Severity const bootcache = beast::Journal::kAll;
};
}
diff --git a/src/ripple/peerfinder/sim/WrappedSink.h b/src/ripple/peerfinder/sim/WrappedSink.h
deleted file mode 100644
index e49896380c..0000000000
--- a/src/ripple/peerfinder/sim/WrappedSink.h
+++ /dev/null
@@ -1,78 +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.
-*/
-//==============================================================================
-
-#ifndef RIPPLE_PEERFINDER_SIM_WRAPPEDSINK_H_INCLUDED
-#define RIPPLE_PEERFINDER_SIM_WRAPPEDSINK_H_INCLUDED
-
-namespace ripple {
-namespace PeerFinder {
-
-/** Wraps a Journal::Sink to prefix its output. */
-class WrappedSink : public beast::Journal::Sink
-{
-public:
- WrappedSink (std::string const& prefix, beast::Journal::Sink& sink)
- : m_prefix (prefix)
- , m_sink (sink)
- {
- }
-
- bool active (beast::Journal::Severity level) const
- { return m_sink.active (level); }
-
- bool console () const
- { return m_sink.console (); }
-
- void console (bool output)
- { m_sink.console (output); }
-
- beast::Journal::Severity severity() const
- { return m_sink.severity(); }
-
- void severity (beast::Journal::Severity level)
- { m_sink.severity (level); }
-
- void write (beast::Journal::Severity level, std::string const& text)
- {
- using beast::Journal;
- std::string s (m_prefix);
- switch (level)
- {
- case Journal::kTrace: s += "Trace: "; break;
- case Journal::kDebug: s += "Debug: "; break;
- case Journal::kInfo: s += "Info : "; break;
- case Journal::kWarning: s += "Warn : "; break;
- case Journal::kError: s += "Error: "; break;
- default:
- case Journal::kFatal: s += "Fatal: "; break;
- };
-
- s+= text;
- m_sink.write (level, s);
- }
-
-private:
- std::string const m_prefix;
- beast::Journal::Sink& m_sink;
-};
-
-}
-}
-
-#endif
diff --git a/src/ripple/rpc/handlers/LogLevel.cpp b/src/ripple/rpc/handlers/LogLevel.cpp
index 9311837f97..81bf4583d0 100644
--- a/src/ripple/rpc/handlers/LogLevel.cpp
+++ b/src/ripple/rpc/handlers/LogLevel.cpp
@@ -39,7 +39,7 @@ Json::Value doLogLevel (RPC::Context& context)
Json::Value lev (Json::objectValue);
lev[jss::base] =
- Logs::toString(Logs::fromSeverity(context.app.logs().severity()));
+ Logs::toString(Logs::fromSeverity(context.app.logs().threshold()));
std::vector< std::pair > logTable (
context.app.logs().partition_severities());
using stringPair = std::map::value_type;
@@ -60,21 +60,21 @@ Json::Value doLogLevel (RPC::Context& context)
// log_level severity
if (!context.params.isMember (jss::partition))
{
- // set base log severity
- context.app.logs().severity(severity);
+ // set base log threshold
+ context.app.logs().threshold(severity);
return Json::objectValue;
}
// log_level partition severity base?
if (context.params.isMember (jss::partition))
{
- // set partition severity
+ // set partition threshold
std::string partition (context.params[jss::partition].asString ());
if (boost::iequals (partition, "base"))
- context.app.logs().severity (severity);
+ context.app.logs().threshold (severity);
else
- context.app.logs().get(partition).severity(severity);
+ context.app.logs().get(partition).threshold(severity);
return Json::objectValue;
}
diff --git a/src/ripple/server/tests/Server_test.cpp b/src/ripple/server/tests/Server_test.cpp
index 17454f9c03..2c02c04cc6 100644
--- a/src/ripple/server/tests/Server_test.cpp
+++ b/src/ripple/server/tests/Server_test.cpp
@@ -77,7 +77,8 @@ public:
public:
TestSink (beast::unit_test::suite& suite)
- : suite_ (suite)
+ : Sink (beast::Journal::kWarning, false)
+ , suite_ (suite)
{
}
@@ -85,6 +86,9 @@ public:
write (beast::Journal::Severity level,
std::string const& text) override
{
+ if (level < threshold())
+ return;
+
suite_.log << text;
}
};
@@ -275,7 +279,7 @@ public:
{
TestSink sink {*this};
TestThread thread;
- sink.severity (beast::Journal::Severity::kAll);
+ sink.threshold (beast::Journal::Severity::kAll);
beast::Journal journal {sink};
TestHandler handler;
auto s = make_Server (handler,
diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp
index fddeac8de0..9a8a8e1fca 100644
--- a/src/ripple/test/jtx/impl/Env.cpp
+++ b/src/ripple/test/jtx/impl/Env.cpp
@@ -92,12 +92,20 @@ class SuiteSink : public beast::Journal::Sink
public:
SuiteSink(std::string const& partition,
+ beast::Journal::Severity threshold,
beast::unit_test::suite& suite)
- : partition_(partition + " ")
+ : Sink (threshold, false)
+ , partition_(partition + " ")
, suite_ (suite)
{
}
+ // For unit testing, always generate logging text.
+ bool active(beast::Journal::Severity level) const override
+ {
+ return true;
+ }
+
void
write(beast::Journal::Severity level,
std::string const& text) override
@@ -113,7 +121,10 @@ public:
default:
case beast::Journal::kFatal: s = "FTL:"; break;
}
- suite_.log << s << partition_ << text;
+
+ // Only write the string if the level at least equals the threshold.
+ if (level >= threshold())
+ suite_.log << s << partition_ << text;
}
};
@@ -132,9 +143,9 @@ public:
std::unique_ptr
makeSink(std::string const& partition,
- beast::Journal::Severity startingLevel) override
+ beast::Journal::Severity threshold) override
{
- return std::make_unique(partition, suite_);
+ return std::make_unique(partition, threshold, suite_);
}
};
@@ -153,14 +164,13 @@ Env::AppBundle::AppBundle(beast::unit_test::suite& suite,
auto timeKeeper_ =
std::make_unique();
timeKeeper = timeKeeper_.get();
- // Hack so we dont have to call Config::setup
+ // Hack so we don't have to call Config::setup
HTTPClient::initializeSSLContext(*config);
owned = make_Application(std::move(config),
std::move(logs), std::move(timeKeeper_));
app = owned.get();
- app->logs().severity(beast::Journal::kError);
+ app->logs().threshold(beast::Journal::kError);
app->setup();
- app->logs().severity(beast::Journal::kError);
timeKeeper->set(
app->getLedgerMaster().getClosedLedger()->info().closeTime);
app->doStart();
diff --git a/src/ripple/unity/peerfinder.cpp b/src/ripple/unity/peerfinder.cpp
index 0d3b307b2a..256b61c746 100644
--- a/src/ripple/unity/peerfinder.cpp
+++ b/src/ripple/unity/peerfinder.cpp
@@ -27,7 +27,6 @@
#include
#include
-#include
#include
#include
#include