From d4d6acdf68eb55df84bd796604400093972ec1de Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 10 Nov 2013 14:57:02 -0800 Subject: [PATCH] Add MSVC Output window Journal config setting Conflicts: src/ripple/peerfinder/impl/Manager.cpp src/ripple/validators/impl/Manager.cpp --- src/BeastConfig.h | 19 +++++++ src/ripple/peerfinder/impl/Manager.cpp | 9 ---- src/ripple/resource/impl/Logic.h | 9 ---- src/ripple/sitefiles/impl/Manager.cpp | 10 ---- src/ripple/validators/impl/Manager.cpp | 9 ---- src/ripple_app/main/LoadManager.cpp | 10 ---- src/ripple_basics/log/LogJournal.cpp | 69 ++++++++++++++++++++++++++ src/ripple_basics/log/LogJournal.h | 61 +++++++---------------- 8 files changed, 107 insertions(+), 89 deletions(-) diff --git a/src/BeastConfig.h b/src/BeastConfig.h index 46d9cd03e..ca84a4806 100644 --- a/src/BeastConfig.h +++ b/src/BeastConfig.h @@ -154,6 +154,25 @@ #define RIPPLE_TRACK_MUTEXES 0 #endif +/** Config: RIPPLE_JOURNAL_MSVC_OUTPUT + A comma separated string of Journal partition names. The partitions which + appear in this list will be logged to the MSVC Output Window if the + process is launched from the IDE. +*/ +#ifndef RIPPLE_JOURNAL_MSVC_OUTPUT +#define RIPPLE_JOURNAL_MSVC_OUTPUT "" +#endif + +/** Config: RIPPLE_JOURNAL_MSVC_OUTPUT_SEVERITY + A Journal severity constant. Log entries below this severity that would be + destined for the MSVC Output Window will not be reported. This has no + effect on partitions not listed in RIPPLE_MSVC_OUTPUT_JOURNALS, or if not + running under the MSVC IDE. +*/ +#ifndef RIPPLE_JOURNAL_MSVC_OUTPUT_SEVERITY +#define RIPPLE_JOURNAL_MSVC_OUTPUT_SEVERITY Journal::kLowestSeverity +#endif + //------------------------------------------------------------------------------ // Here temporarily to turn off new Validations code while it diff --git a/src/ripple/peerfinder/impl/Manager.cpp b/src/ripple/peerfinder/impl/Manager.cpp index b97321d4b..31323c5b2 100644 --- a/src/ripple/peerfinder/impl/Manager.cpp +++ b/src/ripple/peerfinder/impl/Manager.cpp @@ -251,15 +251,6 @@ public: , m_messageTimer (this) , m_cacheTimer (this) { -#if 1 -#if BEAST_MSVC - if (beast_isRunningUnderDebugger()) - { - m_journal.sink().set_console (true); - m_journal.sink().set_severity (Journal::kLowestSeverity); - } -#endif -#endif } ~ManagerImp () diff --git a/src/ripple/resource/impl/Logic.h b/src/ripple/resource/impl/Logic.h index 6bb0894ad..4bca32ad8 100644 --- a/src/ripple/resource/impl/Logic.h +++ b/src/ripple/resource/impl/Logic.h @@ -62,15 +62,6 @@ public: : m_clock (source) , m_journal (journal) { -#if 0 -#if BEAST_MSVC - if (beast_isRunningUnderDebugger()) - { - m_journal.sink().set_console (true); - m_journal.sink().set_severity (Journal::kLowestSeverity); - } -#endif -#endif } virtual ~Logic () diff --git a/src/ripple/sitefiles/impl/Manager.cpp b/src/ripple/sitefiles/impl/Manager.cpp index 9a3fca582..b32bdfc5f 100644 --- a/src/ripple/sitefiles/impl/Manager.cpp +++ b/src/ripple/sitefiles/impl/Manager.cpp @@ -42,16 +42,6 @@ public: , m_logic (journal) , m_journal (journal) { -#if 1 -#if BEAST_MSVC - if (beast_isRunningUnderDebugger()) - { - m_journal.sink().set_console (true); - m_journal.sink().set_severity (Journal::kLowestSeverity); - } -#endif -#endif - // Turned off for now, this is for testing //addURL ("https://ripple.com/ripple.txt"); } diff --git a/src/ripple/validators/impl/Manager.cpp b/src/ripple/validators/impl/Manager.cpp index bd55dc58b..f1e621eb4 100644 --- a/src/ripple/validators/impl/Manager.cpp +++ b/src/ripple/validators/impl/Manager.cpp @@ -158,15 +158,6 @@ public: , m_checkTimer (this) , m_checkSources (false) { -#if 0 -#if BEAST_MSVC - if (beast_isRunningUnderDebugger()) - { - m_journal.sink().set_console (true); - m_journal.sink().set_severity (Journal::kLowestSeverity); - } -#endif -#endif } ~ManagerImp () diff --git a/src/ripple_app/main/LoadManager.cpp b/src/ripple_app/main/LoadManager.cpp index a61fd519a..a3f4202f5 100644 --- a/src/ripple_app/main/LoadManager.cpp +++ b/src/ripple_app/main/LoadManager.cpp @@ -102,16 +102,6 @@ public: , mDeadLock (0) , mCosts (LT_MAX) { -#if 0 -#if BEAST_MSVC - if (beast_isRunningUnderDebugger()) - { - m_journal.sink().set_console (true); - m_journal.sink().set_severity (Journal::kLowestSeverity); - } -#endif -#endif - /** Flags indicating the type of load. Utilization may include any combination of: diff --git a/src/ripple_basics/log/LogJournal.cpp b/src/ripple_basics/log/LogJournal.cpp index 6419746fb..ac20f086c 100644 --- a/src/ripple_basics/log/LogJournal.cpp +++ b/src/ripple_basics/log/LogJournal.cpp @@ -17,6 +17,75 @@ */ //============================================================================== +LogJournal::PartitionSinkBase::PartitionSinkBase (LogPartition& partition) + : m_partition (partition) + , m_severity (Journal::kLowestSeverity) + , m_to_console (false) +{ +#ifdef RIPPLE_JOURNAL_MSVC_OUTPUT + std::string const& list (RIPPLE_JOURNAL_MSVC_OUTPUT); + + std::string::const_iterator first (list.begin()); + for(;;) + { + std::string::const_iterator last (std::find ( + first, list.end(), ',')); + + if (std::equal (first, last, m_partition.getName().begin())) + { + set_console (true); + #ifdef RIPPLE_JOURNAL_MSVC_OUTPUT_SEVERITY + set_severity (RIPPLE_JOURNAL_MSVC_OUTPUT_SEVERITY); + #endif + break; + } + + if (last != list.end()) + first = last + 1; + else + break; + } +#endif +} + +void LogJournal::PartitionSinkBase::write ( + Journal::Severity severity, std::string const& text) +{ + std::string output; + LogSeverity const logSeverity (convertSeverity (severity)); + LogSink::get()->format (output, text, logSeverity, + m_partition.getName()); + LogSink::get()->write (output, logSeverity); +#if BEAST_MSVC + if (m_to_console && beast_isRunningUnderDebugger ()) + Logger::outputDebugString (output.c_str()); +#endif +} + +bool LogJournal::PartitionSinkBase::active ( + Journal::Severity severity) +{ + return m_partition.doLog (convertSeverity (severity)); +} + +bool LogJournal::PartitionSinkBase::console() +{ + return m_to_console; +} + +void LogJournal::PartitionSinkBase::set_severity ( + Journal::Severity severity) +{ + LogSeverity const logSeverity (convertSeverity (severity)); + m_partition.setMinimumSeverity (logSeverity); +} + +void LogJournal::PartitionSinkBase::set_console (bool to_console) +{ + m_to_console = to_console; +} + +//------------------------------------------------------------------------------ LogSeverity LogJournal::convertSeverity (Journal::Severity severity) { diff --git a/src/ripple_basics/log/LogJournal.h b/src/ripple_basics/log/LogJournal.h index 9a3f85c37..75b554850 100644 --- a/src/ripple_basics/log/LogJournal.h +++ b/src/ripple_basics/log/LogJournal.h @@ -30,50 +30,16 @@ public: //-------------------------------------------------------------------------- /** A Journal::Sink that writes to the LogPartition with a given Key. */ - template - class PartitionSink : public Journal::Sink + /** @{ */ + class PartitionSinkBase : public Journal::Sink { public: - PartitionSink () - : m_partition (LogPartition::get ()) - , m_severity (Journal::kLowestSeverity) - , m_to_console (false) - { - } - - void write (Journal::Severity severity, std::string const& text) - { - std::string output; - LogSeverity const logSeverity (convertSeverity (severity)); - LogSink::get()->format (output, text, logSeverity, - m_partition.getName()); - LogSink::get()->write (output, logSeverity); - #if BEAST_MSVC - if (m_to_console && beast_isRunningUnderDebugger ()) - Logger::outputDebugString (output.c_str()); - #endif - } - - bool active (Journal::Severity severity) - { - return m_partition.doLog (convertSeverity (severity)); - } - - bool console() - { - return m_to_console; - } - - void set_severity (Journal::Severity severity) - { - LogSeverity const logSeverity (convertSeverity (severity)); - m_partition.setMinimumSeverity (logSeverity); - } - - void set_console (bool to_console) - { - m_to_console = to_console; - } + explicit PartitionSinkBase (LogPartition& partition); + void write (Journal::Severity severity, std::string const& text); + bool active (Journal::Severity severity); + bool console(); + void set_severity (Journal::Severity severity); + void set_console (bool to_console); private: LogPartition& m_partition; @@ -81,6 +47,17 @@ public: bool m_to_console; }; + template + class PartitionSink : public PartitionSinkBase + { + public: + PartitionSink () + : PartitionSinkBase (LogPartition::get ()) + { + } + }; + /** @} */ + //-------------------------------------------------------------------------- /** Returns a Journal outputting through the LogPartition for the Key. */