mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 12:35:50 +00:00
Journal API improvements
This commit is contained in:
@@ -20,10 +20,11 @@
|
||||
#ifndef BEAST_UTILITY_JOURNAL_H_INCLUDED
|
||||
#define BEAST_UTILITY_JOURNAL_H_INCLUDED
|
||||
|
||||
#include "../SafeBool.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace beast
|
||||
{
|
||||
namespace beast {
|
||||
|
||||
/** A generic endpoint for log messages. */
|
||||
class Journal
|
||||
@@ -57,27 +58,33 @@ public:
|
||||
public:
|
||||
virtual ~Sink () { }
|
||||
|
||||
/** Write text to the sink at the specified severity. */
|
||||
virtual void write (Severity severity, std::string const& text) = 0;
|
||||
|
||||
/** Returns `true` if text at the passed severity produces output. */
|
||||
virtual bool active (Severity severity) = 0;
|
||||
virtual bool active (Severity severity) const = 0;
|
||||
|
||||
/** Returns `true` if a message is also written to the Output Window (MSVC). */
|
||||
virtual bool console () = 0;
|
||||
|
||||
/** Set the minimum severity this sink will report. */
|
||||
virtual void set_severity (Severity severity) = 0;
|
||||
virtual bool console () const = 0;
|
||||
|
||||
/** Set whether messages are also written to the Output Window (MSVC). */
|
||||
virtual void set_console (bool to_console) = 0;
|
||||
virtual void console (bool output) = 0;
|
||||
|
||||
/** Returns the minimum severity level this sink will report. */
|
||||
virtual Severity severity() const = 0;
|
||||
|
||||
/** Set the minimum severity this sink will report. */
|
||||
virtual void severity (Severity level) = 0;
|
||||
|
||||
/** 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;
|
||||
};
|
||||
|
||||
/** Returns a Sink which does nothing. */
|
||||
static Sink& getNullSink ();
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
|
||||
class Stream;
|
||||
|
||||
/** Scoped ostream-based container for writing messages to a Journal. */
|
||||
@@ -122,7 +129,7 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
class Stream
|
||||
class Stream : public SafeBool <Stream>
|
||||
{
|
||||
public:
|
||||
/** Construct a stream which produces no logging output. */
|
||||
@@ -144,7 +151,10 @@ public:
|
||||
Severity severity() const;
|
||||
|
||||
/** Returns `true` if sink logs anything at this stream's severity. */
|
||||
/** @{ */
|
||||
bool active() const;
|
||||
bool asBoolean() const;
|
||||
/** @} */
|
||||
|
||||
/** Output stream support. */
|
||||
/** @{ */
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
|
||||
#include "../Journal.h"
|
||||
|
||||
namespace beast
|
||||
{
|
||||
namespace beast {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -28,27 +27,32 @@ namespace beast
|
||||
class NullJournalSink : public Journal::Sink
|
||||
{
|
||||
public:
|
||||
bool active (Journal::Severity) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool console() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void console (bool)
|
||||
{
|
||||
}
|
||||
|
||||
Journal::Severity severity() const
|
||||
{
|
||||
return Journal::kDisabled;
|
||||
}
|
||||
|
||||
void severity (Journal::Severity)
|
||||
{
|
||||
}
|
||||
|
||||
void write (Journal::Severity, std::string const&)
|
||||
{
|
||||
}
|
||||
|
||||
bool active (Journal::Severity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool console ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_severity (Journal::Severity)
|
||||
{
|
||||
}
|
||||
|
||||
void set_console (bool)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -85,7 +89,7 @@ Journal::ScopedStream::ScopedStream (Stream const& stream, std::ostream& manip (
|
||||
|
||||
Journal::ScopedStream::~ScopedStream ()
|
||||
{
|
||||
if (! m_ostream.str().empty())
|
||||
if (! m_ostream.str().empty() && m_sink.active (m_severity))
|
||||
m_sink.write (m_severity, m_ostream.str());
|
||||
}
|
||||
|
||||
@@ -146,6 +150,11 @@ bool Journal::Stream::active () const
|
||||
return m_sink->active (m_severity);
|
||||
}
|
||||
|
||||
bool Journal::Stream::asBoolean () const
|
||||
{
|
||||
return active();
|
||||
}
|
||||
|
||||
Journal::Stream& Journal::Stream::operator= (Stream const& other)
|
||||
{
|
||||
m_sink = other.m_sink;
|
||||
|
||||
@@ -234,27 +234,32 @@ UnitTests::JournalSink::JournalSink (UnitTests& tests)
|
||||
{
|
||||
}
|
||||
|
||||
void UnitTests::JournalSink::write (Journal::Severity, std::string const& text)
|
||||
{
|
||||
m_tests.logMessage (text);
|
||||
}
|
||||
|
||||
bool UnitTests::JournalSink::active (Journal::Severity)
|
||||
bool UnitTests::JournalSink::active (Journal::Severity) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnitTests::JournalSink::console ()
|
||||
bool UnitTests::JournalSink::console() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void UnitTests::JournalSink::set_severity (Journal::Severity)
|
||||
void UnitTests::JournalSink::console (bool)
|
||||
{
|
||||
}
|
||||
|
||||
void UnitTests::JournalSink::set_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,12 @@ 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);
|
||||
bool active (Journal::Severity severity);
|
||||
bool console ();
|
||||
void set_severity (Journal::Severity severity);
|
||||
void set_console (bool);
|
||||
|
||||
private:
|
||||
UnitTests& m_tests;
|
||||
|
||||
Reference in New Issue
Block a user