Journal option to write to Output window (MSVC)

This commit is contained in:
Vinnie Falco
2013-09-27 18:34:42 -07:00
parent 0b7574ba00
commit ad0064a310
2 changed files with 42 additions and 0 deletions

View File

@@ -105,6 +105,7 @@ public:
Sink& m_sink;
Severity const m_severity;
std::ostringstream mutable m_ostream;
bool m_toOutputWindow;
};
//--------------------------------------------------------------------------
@@ -122,6 +123,12 @@ public:
/** Returns `true` if the sink logs messages at the severity of this stream. */
bool active() const;
/** Returns `true` if the stream also loggs messages to the Output window. */
bool toOutputWindow() const;
/** Also outputs Stream messages to the Output window (MSVC-specific). */
void setOutputWindow (bool toOutputWindow) const;
Sink& sink() const;
Severity severity() const;
@@ -136,6 +143,7 @@ public:
private:
Sink* m_sink;
Severity m_severity;
bool mutable m_toOutputWindow;
};
//--------------------------------------------------------------------------
@@ -151,6 +159,9 @@ public:
/** Returns `true` if the sink logs messages at that severity. */
bool active (Severity severity) const;
/** Sets all streams to also log to the Output window (MSVC-specific). */
void setOutputWindow (bool toOutputWindow) const;
/** Convenience sink streams for each severity level. */
Stream const trace;
Stream const debug;

View File

@@ -54,18 +54,21 @@ 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;
}
@@ -77,6 +80,11 @@ Journal::ScopedStream::~ScopedStream ()
if (! m_ostream.str().empty())
m_sink.write (m_severity, m_ostream.str());
}
#if BEAST_MSVC
if (m_toOutputWindow && beast_isRunningUnderDebugger ())
Logger::outputDebugString (m_ostream.str());
#endif
}
std::ostream& Journal::ScopedStream::operator<< (std::ostream& manip (std::ostream&)) const
@@ -94,18 +102,21 @@ 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)
{
}
@@ -114,6 +125,16 @@ bool Journal::Stream::active () const
return m_sink->active (m_severity);
}
bool Journal::Stream::toOutputWindow() const
{
return m_toOutputWindow;
}
void Journal::Stream::setOutputWindow (bool toOutputWindow) const
{
m_toOutputWindow = toOutputWindow;
}
Journal::Sink& Journal::Stream::sink () const
{
return *m_sink;
@@ -186,4 +207,14 @@ bool Journal::active (Severity severity) const
return m_sink->active (severity);
}
void Journal::setOutputWindow (bool toOutputWindow) const
{
trace.setOutputWindow (toOutputWindow);
debug.setOutputWindow (toOutputWindow);
info.setOutputWindow (toOutputWindow);
warning.setOutputWindow (toOutputWindow);
fatal.setOutputWindow (toOutputWindow);
trace.setOutputWindow (toOutputWindow);
}
}