Journal console output improvements

This commit is contained in:
Vinnie Falco
2013-09-28 16:39:18 -07:00
parent f07515eb88
commit e5e0f527fe
2 changed files with 45 additions and 57 deletions

View File

@@ -38,12 +38,15 @@ public:
/** Severity level of the message. */ /** Severity level of the message. */
enum Severity enum Severity
{ {
kTrace, kLowestSeverity = 0,
kTrace = kLowestSeverity,
kDebug, kDebug,
kInfo, kInfo,
kWarning, kWarning,
kError, kError,
kFatal kFatal,
kDisabled
}; };
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -57,15 +60,16 @@ public:
/** Write text to the sink at the specified severity. */ /** Write text to the sink at the specified severity. */
virtual void write (Severity severity, std::string const& text) = 0; virtual void write (Severity severity, std::string const& text) = 0;
/** Returns `true` if text at the passed severity produces output. /** Returns `true` if text at the passed severity produces output. */
The default implementation always returns `true`. virtual bool active (Severity severity) = 0;
*/
virtual bool active (Severity);
/** Returns `true` if text at the severity goes to the Output window. */ /** Returns `true` if a message is also written to the Output Window (MSVC). */
virtual bool console (); virtual bool console () = 0;
/** Set the minimum severity this sink will report. */
virtual void set_severity (Severity severity) = 0; 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; virtual void set_console (bool to_console) = 0;
}; };
@@ -122,19 +126,26 @@ public:
/** Construct a stream which produces no logging output. */ /** Construct a stream which produces no logging output. */
Stream (); Stream ();
/** Construct a stream that writes to the Sink at the given Severity. */
Stream (Sink& sink, Severity severity); Stream (Sink& sink, Severity severity);
/** Construct or copy another Stream. */
/** @{ */
Stream (Stream const& other); Stream (Stream const& other);
Stream& operator= (Stream const& other); Stream& operator= (Stream const& other);
/** @} */
/** Returns `true` if the sink logs messages at the severity of this stream. */ /** Returns the Sink that this Stream writes to. */
bool active() const;
/** Returns `true` if the stream also logs messages to the Output window. */
bool console() const;
Sink& sink() const; Sink& sink() const;
/** Returns the Severity of messages this Stream reports. */
Severity severity() const; 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; ScopedStream operator<< (std::ostream& manip (std::ostream&)) const;
template <typename T> template <typename T>
@@ -142,6 +153,7 @@ public:
{ {
return ScopedStream (*this, t); return ScopedStream (*this, t);
} }
/** @} */
private: private:
Sink* m_sink; Sink* m_sink;
@@ -155,16 +167,14 @@ public:
Journal (Journal const& other); Journal (Journal const& other);
~Journal (); ~Journal ();
/** Returns the Sink associated with this Journal. */
Sink& sink() const;
/** Returns a stream for this sink, with the specified severity. */ /** Returns a stream for this sink, with the specified severity. */
Stream stream (Severity severity) const; Stream stream (Severity severity) const;
Sink& sink() const; /** Returns `true` if any message would be logged at this severity level. */
/** Returns `true` if the sink logs messages at that severity. */
/** @{ */
bool active (Severity severity) const; bool active (Severity severity) const;
bool console () const;
/** @} */
/** Convenience sink streams for each severity level. */ /** Convenience sink streams for each severity level. */
Stream const trace; Stream const trace;

View File

@@ -22,15 +22,7 @@
namespace beast namespace beast
{ {
bool Journal::Sink::active (Severity) //------------------------------------------------------------------------------
{
return true;
}
bool Journal::Sink::console ()
{
return false;
}
// A Sink that does nothing. // A Sink that does nothing.
class NullJournalSink : public Journal::Sink class NullJournalSink : public Journal::Sink
@@ -45,7 +37,7 @@ public:
return false; return false;
} }
bool console (Journal::Severity) bool console ()
{ {
return false; return false;
} }
@@ -94,11 +86,6 @@ Journal::ScopedStream::~ScopedStream ()
{ {
if (m_sink.active (m_severity)) if (m_sink.active (m_severity))
m_sink.write (m_severity, m_ostream.str()); 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 () Journal::Stream::Stream ()
: m_sink (&getNullSink ()) : m_sink (&getNullSink ())
, m_severity (kFatal) , m_severity (kDisabled)
{ {
} }
@@ -124,6 +111,7 @@ Journal::Stream::Stream (Sink& sink, Severity severity)
: m_sink (&sink) : m_sink (&sink)
, m_severity (severity) , m_severity (severity)
{ {
bassert (severity != kDisabled);
} }
Journal::Stream::Stream (Stream const& other) 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 Journal::Sink& Journal::Stream::sink () const
{ {
return *m_sink; return *m_sink;
@@ -152,6 +130,11 @@ Journal::Severity Journal::Stream::severity () const
return m_severity; return m_severity;
} }
bool Journal::Stream::active () const
{
return m_sink->active (m_severity);
}
Journal::Stream& Journal::Stream::operator= (Stream const& other) Journal::Stream& Journal::Stream::operator= (Stream const& other)
{ {
m_sink = other.m_sink; 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 Journal::Sink& Journal::sink() const
{ {
return *m_sink; 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 bool Journal::active (Severity severity) const
{ {
bassert (severity != kDisabled);
return m_sink->active (severity); return m_sink->active (severity);
} }
bool Journal::console () const
{
return m_sink->console ();
}
} }