From ad0064a310b4ed9e7b1b6d544fd54e45915f37b1 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 27 Sep 2013 18:34:42 -0700 Subject: [PATCH] Journal option to write to Output window (MSVC) --- beast/utility/Journal.h | 11 +++++++++++ beast/utility/impl/Journal.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/beast/utility/Journal.h b/beast/utility/Journal.h index 7198b0cc04..bac08b4431 100644 --- a/beast/utility/Journal.h +++ b/beast/utility/Journal.h @@ -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; diff --git a/beast/utility/impl/Journal.cpp b/beast/utility/impl/Journal.cpp index e0927dd956..38d4efdc73 100644 --- a/beast/utility/impl/Journal.cpp +++ b/beast/utility/impl/Journal.cpp @@ -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); +} + }