Page MenuHomePhabricator

0001-Implemented-suppression-of-log-messages-by-their-log.patch

Authored By
petry
Aug 11 2014, 11:07 AM
Size
4 KB
Referenced Files
None
Subscribers
None

0001-Implemented-suppression-of-log-messages-by-their-log.patch

From facfab88c0abae6b222abe4175c9de8063e85bfb Mon Sep 17 00:00:00 2001
From: Moritz Petry <m.petry@dkfz-heidelberg.de>
Date: Mon, 11 Aug 2014 11:02:19 +0200
Subject: =?UTF-8?q?Implemented=20suppression=20of=20log=20messages=20by=20?=
=?UTF-8?q?their=20log=20level.=0AReplaced=20NoLogMsg=20with=20an=20empty?=
=?UTF-8?q?=20log=20message.?=
---
.../core/include/usModuleSettings.h | 3 ++
.../core/src/module/usModuleSettings.cpp | 13 +++++++++
Core/CppMicroServices/core/src/util/usLog_p.h | 33 +++++++++-------------
3 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/Core/CppMicroServices/core/include/usModuleSettings.h b/Core/CppMicroServices/core/include/usModuleSettings.h
index 5593c72..0c145a4 100644
--- a/Core/CppMicroServices/core/include/usModuleSettings.h
+++ b/Core/CppMicroServices/core/include/usModuleSettings.h
@@ -140,6 +140,9 @@ public:
*/
static std::string GetStoragePath();
+ static void SetLogLevel(int l);
+ static int GetLogLevel();
+
private:
// purposely not implemented
diff --git a/Core/CppMicroServices/core/src/module/usModuleSettings.cpp b/Core/CppMicroServices/core/src/module/usModuleSettings.cpp
index 9249e18..036a512 100644
--- a/Core/CppMicroServices/core/src/module/usModuleSettings.cpp
+++ b/Core/CppMicroServices/core/src/module/usModuleSettings.cpp
@@ -101,6 +101,7 @@ struct ModuleSettingsPrivate : public MultiThreaded<>
bool autoLoadingEnabled;
bool autoLoadingDisabled;
std::string storagePath;
+ int logLevel;
};
US_GLOBAL_STATIC(ModuleSettingsPrivate, moduleSettingsPrivate)
@@ -172,4 +173,16 @@ std::string ModuleSettings::GetStoragePath()
return moduleSettingsPrivate()->storagePath;
}
+void ModuleSettings::SetLogLevel(int l)
+{
+ US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
+ moduleSettingsPrivate()->logLevel = l;
+}
+
+int ModuleSettings::GetLogLevel()
+{
+ US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
+ return moduleSettingsPrivate()->logLevel;
+}
+
US_END_NAMESPACE
diff --git a/Core/CppMicroServices/core/src/util/usLog_p.h b/Core/CppMicroServices/core/src/util/usLog_p.h
index bd65a8f..d88f1e6 100644
--- a/Core/CppMicroServices/core/src/util/usLog_p.h
+++ b/Core/CppMicroServices/core/src/util/usLog_p.h
@@ -23,6 +23,7 @@
#define USLOG_P_H
#include <usCoreConfig.h>
+#include <usModuleSettings.h>
#include <iostream>
#include <sstream>
@@ -37,6 +38,14 @@ struct LogMsg {
: type(static_cast<MsgType>(t)), enabled(true), buffer()
{ buffer << "In " << func << " at " << file << ":" << ln << " : "; }
+ LogMsg()
+ : type(DebugMsg), enabled(false), buffer()
+ {}
+
+ LogMsg(const LogMsg& other)
+ : type(other.type), enabled(other.enabled), buffer()
+ {}
+
~LogMsg() { if(enabled) message_output(type, buffer.str().c_str()); }
template<typename T>
@@ -59,41 +68,27 @@ private:
std::stringstream buffer;
};
-struct NoLogMsg {
-
- template<typename T>
- NoLogMsg& operator<<(T)
- {
- return *this;
- }
-
- NoLogMsg& operator()(bool)
- {
- return *this;
- }
-
-};
US_END_NAMESPACE
#if defined(US_ENABLE_DEBUG_OUTPUT)
- #define US_DEBUG US_PREPEND_NAMESPACE(LogMsg)(0, __FILE__, __LINE__, __FUNCTION__)
+ #define US_DEBUG (US_PREPEND_NAMESPACE(ModuleSettings)::GetLogLevel() > 0 ? US_PREPEND_NAMESPACE(LogMsg)() : US_PREPEND_NAMESPACE(LogMsg)(0, __FILE__, __LINE__, __FUNCTION__))
#else
- #define US_DEBUG true ? US_PREPEND_NAMESPACE(NoLogMsg)() : US_PREPEND_NAMESPACE(NoLogMsg)()
+ #define US_DEBUG true ? US_PREPEND_NAMESPACE(LogMsg)() : US_PREPEND_NAMESPACE(LogMsg)()
#endif
#if !defined(US_NO_INFO_OUTPUT)
- #define US_INFO US_PREPEND_NAMESPACE(LogMsg)(1, __FILE__, __LINE__, __FUNCTION__)
+ #define US_INFO (US_PREPEND_NAMESPACE(ModuleSettings)::GetLogLevel() > 1 ? US_PREPEND_NAMESPACE(LogMsg)() : US_PREPEND_NAMESPACE(LogMsg)(1, __FILE__, __LINE__, __FUNCTION__))
#else
#define US_INFO true ? US_PREPEND_NAMESPACE(NoLogMsg)() : US_PREPEND_NAMESPACE(NoLogMsg)()
#endif
#if !defined(US_NO_WARNING_OUTPUT)
- #define US_WARN US_PREPEND_NAMESPACE(LogMsg)(2, __FILE__, __LINE__, __FUNCTION__)
+ #define US_WARN (US_PREPEND_NAMESPACE(ModuleSettings)::GetLogLevel() > 2 ? US_PREPEND_NAMESPACE(LogMsg)() : US_PREPEND_NAMESPACE(LogMsg)(2, __FILE__, __LINE__, __FUNCTION__))
#else
#define US_WARN true ? US_PREPEND_NAMESPACE(LogMsg)() : US_PREPEND_NAMESPACE(LogMsg)()
#endif
-#define US_ERROR US_PREPEND_NAMESPACE(LogMsg)(3, __FILE__, __LINE__, __FUNCTION__)
+#define US_ERROR (US_PREPEND_NAMESPACE(ModuleSettings)::GetLogLevel() > 3 ? US_PREPEND_NAMESPACE(LogMsg)() : US_PREPEND_NAMESPACE(LogMsg)(3, __FILE__, __LINE__, __FUNCTION__))
#endif // USLOG_P_H
--
1.9.1

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1100
Default Alt Text
0001-Implemented-suppression-of-log-messages-by-their-log.patch (4 KB)

Event Timeline