mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 15:35:50 +00:00
Journal console output improvements
This commit is contained in:
@@ -38,12 +38,15 @@ public:
|
||||
/** Severity level of the message. */
|
||||
enum Severity
|
||||
{
|
||||
kTrace,
|
||||
kLowestSeverity = 0,
|
||||
kTrace = kLowestSeverity,
|
||||
kDebug,
|
||||
kInfo,
|
||||
kWarning,
|
||||
kError,
|
||||
kFatal
|
||||
kFatal,
|
||||
|
||||
kDisabled
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -57,15 +60,16 @@ public:
|
||||
/** 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.
|
||||
The default implementation always returns `true`.
|
||||
*/
|
||||
virtual bool active (Severity);
|
||||
/** Returns `true` if text at the passed severity produces output. */
|
||||
virtual bool active (Severity severity) = 0;
|
||||
|
||||
/** Returns `true` if text at the severity goes to the Output window. */
|
||||
virtual bool console ();
|
||||
/** 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;
|
||||
|
||||
/** Set whether messages are also written to the Output Window (MSVC). */
|
||||
virtual void set_console (bool to_console) = 0;
|
||||
};
|
||||
|
||||
@@ -122,19 +126,26 @@ public:
|
||||
/** Construct a stream which produces no logging output. */
|
||||
Stream ();
|
||||
|
||||
/** Construct a stream that writes to the Sink at the given Severity. */
|
||||
Stream (Sink& sink, Severity severity);
|
||||
|
||||
/** Construct or copy another Stream. */
|
||||
/** @{ */
|
||||
Stream (Stream const& other);
|
||||
Stream& operator= (Stream const& other);
|
||||
/** @} */
|
||||
|
||||
/** Returns `true` if the sink logs messages at the severity of this stream. */
|
||||
bool active() const;
|
||||
|
||||
/** Returns `true` if the stream also logs messages to the Output window. */
|
||||
bool console() const;
|
||||
|
||||
/** Returns the Sink that this Stream writes to. */
|
||||
Sink& sink() const;
|
||||
|
||||
/** Returns the Severity of messages this Stream reports. */
|
||||
Severity severity() const;
|
||||
|
||||
/** Returns `true` if sink logs anything at this stream's severity. */
|
||||
bool active() const;
|
||||
|
||||
/** Output stream support. */
|
||||
/** @{ */
|
||||
ScopedStream operator<< (std::ostream& manip (std::ostream&)) const;
|
||||
|
||||
template <typename T>
|
||||
@@ -142,6 +153,7 @@ public:
|
||||
{
|
||||
return ScopedStream (*this, t);
|
||||
}
|
||||
/** @} */
|
||||
|
||||
private:
|
||||
Sink* m_sink;
|
||||
@@ -155,16 +167,14 @@ public:
|
||||
Journal (Journal const& other);
|
||||
~Journal ();
|
||||
|
||||
/** Returns the Sink associated with this Journal. */
|
||||
Sink& sink() const;
|
||||
|
||||
/** Returns a stream for this sink, with the specified severity. */
|
||||
Stream stream (Severity severity) const;
|
||||
|
||||
Sink& sink() const;
|
||||
|
||||
/** Returns `true` if the sink logs messages at that severity. */
|
||||
/** @{ */
|
||||
/** Returns `true` if any message would be logged at this severity level. */
|
||||
bool active (Severity severity) const;
|
||||
bool console () const;
|
||||
/** @} */
|
||||
|
||||
/** Convenience sink streams for each severity level. */
|
||||
Stream const trace;
|
||||
|
||||
@@ -22,15 +22,7 @@
|
||||
namespace beast
|
||||
{
|
||||
|
||||
bool Journal::Sink::active (Severity)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Journal::Sink::console ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// A Sink that does nothing.
|
||||
class NullJournalSink : public Journal::Sink
|
||||
@@ -45,7 +37,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool console (Journal::Severity)
|
||||
bool console ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -94,11 +86,6 @@ Journal::ScopedStream::~ScopedStream ()
|
||||
{
|
||||
if (m_sink.active (m_severity))
|
||||
m_sink.write (m_severity, m_ostream.str());
|
||||
|
||||
#if BEAST_MSVC
|
||||
if (m_sink.console () && beast_isRunningUnderDebugger ())
|
||||
Logger::outputDebugString (m_ostream.str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +103,7 @@ std::ostringstream& Journal::ScopedStream::ostream () const
|
||||
|
||||
Journal::Stream::Stream ()
|
||||
: m_sink (&getNullSink ())
|
||||
, m_severity (kFatal)
|
||||
, m_severity (kDisabled)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -124,6 +111,7 @@ Journal::Stream::Stream (Sink& sink, Severity severity)
|
||||
: m_sink (&sink)
|
||||
, m_severity (severity)
|
||||
{
|
||||
bassert (severity != kDisabled);
|
||||
}
|
||||
|
||||
Journal::Stream::Stream (Stream const& other)
|
||||
@@ -132,16 +120,6 @@ Journal::Stream::Stream (Stream const& other)
|
||||
{
|
||||
}
|
||||
|
||||
bool Journal::Stream::active () const
|
||||
{
|
||||
return m_sink->active (m_severity);
|
||||
}
|
||||
|
||||
bool Journal::Stream::console() const
|
||||
{
|
||||
return m_sink->console ();
|
||||
}
|
||||
|
||||
Journal::Sink& Journal::Stream::sink () const
|
||||
{
|
||||
return *m_sink;
|
||||
@@ -152,6 +130,11 @@ Journal::Severity Journal::Stream::severity () const
|
||||
return m_severity;
|
||||
}
|
||||
|
||||
bool Journal::Stream::active () const
|
||||
{
|
||||
return m_sink->active (m_severity);
|
||||
}
|
||||
|
||||
Journal::Stream& Journal::Stream::operator= (Stream const& other)
|
||||
{
|
||||
m_sink = other.m_sink;
|
||||
@@ -203,25 +186,20 @@ Journal::~Journal ()
|
||||
{
|
||||
}
|
||||
|
||||
Journal::Stream Journal::stream (Severity severity) const
|
||||
{
|
||||
return Stream (*m_sink, severity);
|
||||
}
|
||||
|
||||
Journal::Sink& Journal::sink() const
|
||||
{
|
||||
return *m_sink;
|
||||
}
|
||||
|
||||
/** Returns `true` if the sink logs messages at that severity. */
|
||||
Journal::Stream Journal::stream (Severity severity) const
|
||||
{
|
||||
return Stream (*m_sink, severity);
|
||||
}
|
||||
|
||||
bool Journal::active (Severity severity) const
|
||||
{
|
||||
bassert (severity != kDisabled);
|
||||
return m_sink->active (severity);
|
||||
}
|
||||
|
||||
bool Journal::console () const
|
||||
{
|
||||
return m_sink->console ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user