From a5194c9f2a09f49a1ffebcb4dd5a659029cbd568 Mon Sep 17 00:00:00 2001 From: Moritz Petry Date: Fri, 8 Aug 2014 16:40:48 +0200 Subject: implemented methods to disable and enable different log types --- .../src/internal/berryQtPlatformLogModel.h | 5 +++++ Core/Code/IO/mitkLog.cpp | 5 +++++ Core/Code/IO/mitkLog.h | 2 ++ Utilities/mbilog/mbilog.cpp | 22 +++++++++++++++++++++- Utilities/mbilog/mbilog.h | 8 ++++++++ Utilities/mbilog/mbilogBackendBase.h | 7 +++++++ Utilities/mbilog/mbilogBackendCout.cpp | 4 ++++ Utilities/mbilog/mbilogBackendCout.h | 2 ++ 8 files changed, 54 insertions(+), 1 deletion(-) diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt.log/src/internal/berryQtPlatformLogModel.h b/BlueBerry/Bundles/org.blueberry.ui.qt.log/src/internal/berryQtPlatformLogModel.h index eb8a818..7b11d50 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt.log/src/internal/berryQtPlatformLogModel.h +++ b/BlueBerry/Bundles/org.blueberry.ui.qt.log/src/internal/berryQtPlatformLogModel.h @@ -184,6 +184,11 @@ private: myModel->addLogEntry(l); } + mbilog::OutputType GetOutputType() + { + return mbilog::Console; + } + void Deactivate() { deactivated=true; diff --git a/Core/Code/IO/mitkLog.cpp b/Core/Code/IO/mitkLog.cpp index 620d12e..9c11ff3 100644 --- a/Core/Code/IO/mitkLog.cpp +++ b/Core/Code/IO/mitkLog.cpp @@ -232,3 +232,8 @@ bool mitk::LoggingBackend::CheckIfFileExists(const std::string& filename) File.close(); return returnValue; } + +mbilog::OutputType mitk::LoggingBackend::GetOutputType() +{ + return mbilog::Console; +} diff --git a/Core/Code/IO/mitkLog.h b/Core/Code/IO/mitkLog.h index 8efe212..7bcd118 100644 --- a/Core/Code/IO/mitkLog.h +++ b/Core/Code/IO/mitkLog.h @@ -93,6 +93,8 @@ namespace mitk */ static void CatchLogFileCommandLineParameter(int &argc,char **argv); + virtual mbilog::OutputType GetOutputType(); + protected: /** Checks if a file exists. * @return Returns true if the file exists, false if not. diff --git a/Utilities/mbilog/mbilog.cpp b/Utilities/mbilog/mbilog.cpp index 95f8ae5..8e3e5b5 100644 --- a/Utilities/mbilog/mbilog.cpp +++ b/Utilities/mbilog/mbilog.cpp @@ -15,10 +15,12 @@ See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include +#include #include "mbilog.h" static std::list backends; +static std::set disabledBackendTypes; namespace mbilog { @@ -63,7 +65,25 @@ void mbilog::DistributeToBackends(mbilog::LogMessage &l) //iterate through all registered images and call the ProcessMessage() methods of the backends std::list::iterator i; for(i = backends.begin(); i != backends.end(); i++) - (*i)->ProcessMessage(l); + { + if (IsBackendEnabled((*i)->GetOutputType())) + (*i)->ProcessMessage(l); + } +} + +bool mbilog::EnableBackends(OutputType type) +{ + disabledBackendTypes.erase(type); +} + +bool mbilog::DisableBackends(OutputType type) +{ + disabledBackendTypes.insert(type); +} + +bool mbilog::IsBackendEnabled(OutputType type) +{ + return disabledBackendTypes.find(type) == disabledBackendTypes.end(); } diff --git a/Utilities/mbilog/mbilog.h b/Utilities/mbilog/mbilog.h index f814d67..cdfb899 100644 --- a/Utilities/mbilog/mbilog.h +++ b/Utilities/mbilog/mbilog.h @@ -53,6 +53,11 @@ namespace mbilog { * using the bit shift operator (<<). Should only be used by the macros defined in the file mbilog.h * \ingroup mbilog */ + + bool MBILOG_DLL_API EnableBackends(OutputType type); + bool MBILOG_DLL_API DisableBackends(OutputType type); + bool MBILOG_DLL_API IsBackendEnabled(OutputType type); + class MBILOG_DLL_API PseudoStream { protected: @@ -221,6 +226,9 @@ namespace mbilog { #define MBI_ERROR mbilog::PseudoStream(mbilog::Error,__FILE__,__LINE__,__FUNCTION__) #define MBI_FATAL mbilog::PseudoStream(mbilog::Fatal,__FILE__,__LINE__,__FUNCTION__) +#define MBILOG_DISABLE_BACKENDS(type) static bool disabled = mbilog::DisableBackends(type); +#define MBILOG_ENABLE_BACKENDS(type) static bool enabled = mbilog::EnableBackends(type); + /** \brief Macro for the debug messages. The messages are disabled if the cmake variable MBILOG_ENABLE_DEBUG is false. */ #ifdef MBILOG_ENABLE_DEBUG #define MBI_DEBUG mbilog::PseudoStream(mbilog::Debug,__FILE__,__LINE__,__FUNCTION__) diff --git a/Utilities/mbilog/mbilogBackendBase.h b/Utilities/mbilog/mbilogBackendBase.h index 514e732..eb7287c 100644 --- a/Utilities/mbilog/mbilogBackendBase.h +++ b/Utilities/mbilog/mbilogBackendBase.h @@ -23,6 +23,11 @@ See LICENSE.txt or http://www.mitk.org for details. namespace mbilog{ +enum MBILOG_DLL_API OutputType{ + Console = 0, + File, + Other = 100 +}; /** * \brief This class is an interface for logging backends that can be registered in the mbi logging mechanism. * @@ -42,6 +47,8 @@ namespace mbilog{ * */ virtual void ProcessMessage(const mbilog::LogMessage& logMessage)=0; + + virtual OutputType GetOutputType()=0; }; } diff --git a/Utilities/mbilog/mbilogBackendCout.cpp b/Utilities/mbilog/mbilogBackendCout.cpp index 6f40953..6e1f73b 100644 --- a/Utilities/mbilog/mbilogBackendCout.cpp +++ b/Utilities/mbilog/mbilogBackendCout.cpp @@ -44,6 +44,10 @@ void mbilog::BackendCout::ProcessMessage(const mbilog::LogMessage& l) FormatSmart(l); } +mbilog::OutputType mbilog::BackendCout::GetOutputType() +{ + return mbilog::Console; +} diff --git a/Utilities/mbilog/mbilogBackendCout.h b/Utilities/mbilog/mbilogBackendCout.h index 0822a7a..d1936df 100644 --- a/Utilities/mbilog/mbilogBackendCout.h +++ b/Utilities/mbilog/mbilogBackendCout.h @@ -51,6 +51,8 @@ namespace mbilog{ */ void SetFull(bool full); + virtual OutputType GetOutputType(); + private: /** \brief The formatting mode of this backend. True is full/long message formatting mode. False is short/smart -- 1.9.1