Add console feature to Journal

This commit is contained in:
Vinnie Falco
2013-09-27 19:39:31 -07:00
parent ad0064a310
commit 3f6e7aa05a
2 changed files with 48 additions and 37 deletions

View File

@@ -27,6 +27,11 @@ bool Journal::Sink::active (Severity)
return true;
}
bool Journal::Sink::console ()
{
return false;
}
// A Sink that does nothing.
class NullJournalSink : public Journal::Sink
{
@@ -39,6 +44,19 @@ public:
{
return false;
}
bool console (Journal::Severity)
{
return false;
}
void set_severity (Journal::Severity)
{
}
void set_console (bool)
{
}
};
//------------------------------------------------------------------------------
@@ -54,37 +72,34 @@ Journal::Sink& Journal::getNullSink ()
Journal::ScopedStream::ScopedStream (Stream const& stream)
: m_sink (stream.sink())
, m_severity (stream.severity())
, m_toOutputWindow (stream.toOutputWindow())
{
}
Journal::ScopedStream::ScopedStream (ScopedStream const& other)
: m_sink (other.m_sink)
, m_severity (other.m_severity)
, m_toOutputWindow (other.m_toOutputWindow)
{
}
Journal::ScopedStream::ScopedStream (Stream const& stream, std::ostream& manip (std::ostream&))
: m_sink (stream.sink())
, m_severity (stream.severity())
, m_toOutputWindow (stream.toOutputWindow())
{
m_ostream << manip;
}
Journal::ScopedStream::~ScopedStream ()
{
if (m_sink.active (m_severity))
if (! m_ostream.str().empty())
{
if (! m_ostream.str().empty())
if (m_sink.active (m_severity))
m_sink.write (m_severity, m_ostream.str());
}
#if BEAST_MSVC
if (m_toOutputWindow && beast_isRunningUnderDebugger ())
Logger::outputDebugString (m_ostream.str());
#endif
#if BEAST_MSVC
if (m_sink.console () && beast_isRunningUnderDebugger ())
Logger::outputDebugString (m_ostream.str());
#endif
}
}
std::ostream& Journal::ScopedStream::operator<< (std::ostream& manip (std::ostream&)) const
@@ -102,21 +117,18 @@ std::ostringstream& Journal::ScopedStream::ostream () const
Journal::Stream::Stream ()
: m_sink (&getNullSink ())
, m_severity (kFatal)
, m_toOutputWindow (false)
{
}
Journal::Stream::Stream (Sink& sink, Severity severity)
: m_sink (&sink)
, m_severity (severity)
, m_toOutputWindow (false)
{
}
Journal::Stream::Stream (Stream const& other)
: m_sink (other.m_sink)
, m_severity (other.m_severity)
, m_toOutputWindow (other.m_toOutputWindow)
{
}
@@ -125,14 +137,9 @@ bool Journal::Stream::active () const
return m_sink->active (m_severity);
}
bool Journal::Stream::toOutputWindow() const
bool Journal::Stream::console() const
{
return m_toOutputWindow;
}
void Journal::Stream::setOutputWindow (bool toOutputWindow) const
{
m_toOutputWindow = toOutputWindow;
return m_sink->console ();
}
Journal::Sink& Journal::Stream::sink () const
@@ -201,20 +208,20 @@ 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. */
bool Journal::active (Severity severity) const
{
return m_sink->active (severity);
}
void Journal::setOutputWindow (bool toOutputWindow) const
bool Journal::console () const
{
trace.setOutputWindow (toOutputWindow);
debug.setOutputWindow (toOutputWindow);
info.setOutputWindow (toOutputWindow);
warning.setOutputWindow (toOutputWindow);
fatal.setOutputWindow (toOutputWindow);
trace.setOutputWindow (toOutputWindow);
return m_sink->console ();
}
}