mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +00:00
Refactor some Journal::Sink members
This commit is contained in:
@@ -56,28 +56,34 @@ public:
|
||||
class Sink
|
||||
{
|
||||
public:
|
||||
virtual ~Sink () { }
|
||||
Sink ();
|
||||
|
||||
virtual ~Sink () = 0;
|
||||
|
||||
/** Returns `true` if text at the passed severity produces output. */
|
||||
virtual bool active (Severity severity) const = 0;
|
||||
virtual bool active (Severity level) const;
|
||||
|
||||
/** Returns `true` if a message is also written to the Output Window (MSVC). */
|
||||
virtual bool console () const = 0;
|
||||
virtual bool console () const;
|
||||
|
||||
/** Set whether messages are also written to the Output Window (MSVC). */
|
||||
virtual void console (bool output) = 0;
|
||||
virtual void console (bool output);
|
||||
|
||||
/** Returns the minimum severity level this sink will report. */
|
||||
virtual Severity severity() const = 0;
|
||||
virtual Severity severity() const;
|
||||
|
||||
/** Set the minimum severity this sink will report. */
|
||||
virtual void severity (Severity level) = 0;
|
||||
virtual void severity (Severity level);
|
||||
|
||||
/** Write text to the sink at the specified severity.
|
||||
The caller is responsible for checking the minimum severity level
|
||||
before using this function.
|
||||
*/
|
||||
virtual void write (Severity level, std::string const& text) = 0;
|
||||
|
||||
private:
|
||||
Severity m_severity;
|
||||
bool m_console;
|
||||
};
|
||||
|
||||
/** Returns a Sink which does nothing. */
|
||||
|
||||
@@ -65,6 +65,43 @@ Journal::Sink& Journal::getNullSink ()
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Journal::Sink::Sink ()
|
||||
: m_severity (kLowestSeverity)
|
||||
, m_console (false)
|
||||
{
|
||||
}
|
||||
|
||||
Journal::Sink::~Sink ()
|
||||
{
|
||||
}
|
||||
|
||||
bool Journal::Sink::active (Severity level) const
|
||||
{
|
||||
return level >= m_severity;
|
||||
}
|
||||
|
||||
bool Journal::Sink::console () const
|
||||
{
|
||||
return m_console;
|
||||
}
|
||||
|
||||
void Journal::Sink::console (bool output)
|
||||
{
|
||||
m_console = output;
|
||||
}
|
||||
|
||||
Journal::Severity Journal::Sink::severity () const
|
||||
{
|
||||
return m_severity;
|
||||
}
|
||||
|
||||
void Journal::Sink::severity (Severity level)
|
||||
{
|
||||
m_severity = level;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Journal::ScopedStream::ScopedStream (Stream const& stream)
|
||||
: m_sink (stream.sink())
|
||||
, m_severity (stream.severity())
|
||||
|
||||
@@ -235,29 +235,6 @@ UnitTests::JournalSink::JournalSink (UnitTests& tests)
|
||||
{
|
||||
}
|
||||
|
||||
bool UnitTests::JournalSink::active (Journal::Severity) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnitTests::JournalSink::console() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void UnitTests::JournalSink::console (bool)
|
||||
{
|
||||
}
|
||||
|
||||
Journal::Severity UnitTests::JournalSink::severity() const
|
||||
{
|
||||
return Journal::kLowestSeverity;
|
||||
}
|
||||
|
||||
void UnitTests::JournalSink::severity (Journal::Severity)
|
||||
{
|
||||
}
|
||||
|
||||
void UnitTests::JournalSink::write (Journal::Severity, std::string const& text)
|
||||
{
|
||||
m_tests.logMessage (text);
|
||||
|
||||
@@ -517,11 +517,6 @@ private:
|
||||
{
|
||||
public:
|
||||
explicit JournalSink (UnitTests& tests);
|
||||
bool active (Journal::Severity severity) const;
|
||||
bool console () const;
|
||||
void console (bool);
|
||||
Journal::Severity severity() const;
|
||||
void severity (Journal::Severity severity);
|
||||
void write (Journal::Severity severity, std::string const& text);
|
||||
|
||||
private:
|
||||
|
||||
@@ -17,38 +17,13 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
bool LogPartition::active (Journal::Severity severity) const
|
||||
{
|
||||
return convertSeverity (severity) >= mMinSeverity;
|
||||
}
|
||||
|
||||
bool LogPartition::console () const
|
||||
{
|
||||
return m_console;
|
||||
}
|
||||
|
||||
void LogPartition::console (bool output)
|
||||
{
|
||||
m_console = output;
|
||||
}
|
||||
|
||||
Journal::Severity LogPartition::severity() const
|
||||
{
|
||||
return convertLogSeverity (mMinSeverity);
|
||||
}
|
||||
|
||||
void LogPartition::severity (Journal::Severity level)
|
||||
{
|
||||
setMinimumSeverity (convertSeverity (level));
|
||||
}
|
||||
|
||||
void LogPartition::write (Journal::Severity level, std::string const& text)
|
||||
{
|
||||
std::string output;
|
||||
LogSeverity const logSeverity (convertSeverity (level));
|
||||
LogSink::get()->format (output, text, logSeverity, mName);
|
||||
LogSink::get()->write (output, logSeverity);
|
||||
if (m_console)
|
||||
if (console ())
|
||||
LogSink::get()->write_console (output);
|
||||
}
|
||||
|
||||
@@ -56,17 +31,16 @@ void LogPartition::write (Journal::Severity level, std::string const& text)
|
||||
|
||||
LogPartition::LogPartition (std::string const& name)
|
||||
: mNextLog (headLog)
|
||||
, mMinSeverity (lsWARNING)
|
||||
, mName (canonicalFileName (name.c_str()))
|
||||
, m_console (false)
|
||||
{
|
||||
severity (Journal::kWarning);
|
||||
// VFALCO TODO Use an intrusive list.
|
||||
headLog = this;
|
||||
}
|
||||
|
||||
bool LogPartition::doLog (LogSeverity s) const
|
||||
{
|
||||
return s >= mMinSeverity;
|
||||
return s >= getSeverity();
|
||||
}
|
||||
|
||||
std::string const& LogPartition::getName () const
|
||||
@@ -76,12 +50,12 @@ std::string const& LogPartition::getName () const
|
||||
|
||||
LogSeverity LogPartition::getSeverity() const
|
||||
{
|
||||
return mMinSeverity;
|
||||
return convertSeverity (severity ());
|
||||
}
|
||||
|
||||
void LogPartition::setMinimumSeverity (LogSeverity severity)
|
||||
void LogPartition::setMinimumSeverity (LogSeverity level)
|
||||
{
|
||||
mMinSeverity = severity;
|
||||
severity (convertLogSeverity (level));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -110,19 +84,19 @@ LogPartition* LogPartition::find (std::string const& name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void LogPartition::setSeverity (LogSeverity severity)
|
||||
void LogPartition::setSeverity (LogSeverity level)
|
||||
{
|
||||
for (LogPartition* p = headLog; p != nullptr; p = p->mNextLog)
|
||||
p->mMinSeverity = severity;
|
||||
p->setMinimumSeverity (level);
|
||||
}
|
||||
|
||||
bool LogPartition::setSeverity (const std::string& partition, LogSeverity severity)
|
||||
bool LogPartition::setSeverity (const std::string& partition, LogSeverity level)
|
||||
{
|
||||
LogPartition* const p (find (partition));
|
||||
|
||||
if (p)
|
||||
{
|
||||
p->mMinSeverity = severity;
|
||||
p->setMinimumSeverity (level);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -153,7 +127,8 @@ LogPartition::Severities LogPartition::getSeverities ()
|
||||
LogPartition::Severities result;
|
||||
|
||||
for (LogPartition* l = headLog; l != nullptr; l = l->mNextLog)
|
||||
result.push_back (std::make_pair (l->mName, Log::severityToString (l->mMinSeverity)));
|
||||
result.push_back (std::make_pair (
|
||||
l->mName, Log::severityToString (l->getSeverity ())));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,6 @@ public:
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
bool active (Journal::Severity severity) const;
|
||||
bool console () const;
|
||||
void console (bool output);
|
||||
Journal::Severity severity() const;
|
||||
void severity (Journal::Severity level);
|
||||
void write (Journal::Severity level, std::string const& text);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -112,9 +107,7 @@ private:
|
||||
static LogPartition* headLog;
|
||||
|
||||
LogPartition* mNextLog;
|
||||
LogSeverity mMinSeverity;
|
||||
std::string mName;
|
||||
bool m_console;
|
||||
};
|
||||
|
||||
#define SETUP_LOG(Class) \
|
||||
|
||||
Reference in New Issue
Block a user