summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2012-01-23 01:32:08 +0000
committerChris Wilson <chris+github@qwirx.com>2012-01-23 01:32:08 +0000
commitcbc2639aec361e3832cc1adfc28079b49a89f0ad (patch)
treea58c866e4abb65c300d86e39801e3f5ee44c52d3 /lib
parentec36628676c99aa10f14f6f142d84e57143eda90 (diff)
Allow overriding Logging::Guard to dump stack backtraces as well.
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Box.h20
-rw-r--r--lib/common/Logging.cpp3
-rw-r--r--lib/common/Logging.h16
3 files changed, 37 insertions, 2 deletions
diff --git a/lib/common/Box.h b/lib/common/Box.h
index 4a30891a..6ef797be 100644
--- a/lib/common/Box.h
+++ b/lib/common/Box.h
@@ -17,6 +17,8 @@
#include "BoxPlatform.h"
+#include <memory>
+
// uncomment this line to enable full memory leak finding on all
// malloc-ed blocks (at least, ones used by the STL)
//#define MEMLEAKFINDER_FULL_MALLOC_MONITORING
@@ -104,8 +106,15 @@
#define THROW_EXCEPTION(type, subtype) \
{ \
if(!HideExceptionMessageGuard::ExceptionsHidden() \
- || Logging::IsEnabled(Log::EVERYTHING)) \
+ || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
{ \
+ std::auto_ptr<Logging::Guard> guard; \
+ \
+ if(Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
+ { \
+ guard.reset(new Logging::Guard(Log::EVERYTHING)); \
+ } \
+ \
OPTIONAL_DO_BACKTRACE \
BOX_WARNING("Exception thrown: " \
#type "(" #subtype ") " \
@@ -119,8 +128,15 @@
std::ostringstream _box_throw_line; \
_box_throw_line << message; \
if(!HideExceptionMessageGuard::ExceptionsHidden() \
- || Logging::IsEnabled(Log::EVERYTHING)) \
+ || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
{ \
+ std::auto_ptr<Logging::Guard> guard; \
+ \
+ if(Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
+ { \
+ guard.reset(new Logging::Guard(Log::EVERYTHING)); \
+ } \
+ \
OPTIONAL_DO_BACKTRACE \
BOX_WARNING("Exception thrown: " \
#type "(" #subtype ") (" << message << \
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp
index f7f72713..f0cf74b4 100644
--- a/lib/common/Logging.cpp
+++ b/lib/common/Logging.cpp
@@ -46,6 +46,9 @@ Log::Level Logging::sGlobalLevel = Log::EVERYTHING;
Logging Logging::sGlobalLogging; //automatic initialisation
std::string Logging::sProgramName;
+int Logging::Guard::sGuardCount = 0;
+Log::Level Logging::Guard::sOriginalLevel = Log::INVALID;
+
Logging::Logging()
{
ASSERT(!spConsole);
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 4ddf760d..1fcbe59e 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -303,17 +303,33 @@ class Logging
{
private:
Log::Level mOldLevel;
+ static int sGuardCount;
+ static Log::Level sOriginalLevel;
public:
Guard(Log::Level newLevel)
{
mOldLevel = Logging::GetGlobalLevel();
+ if(sGuardCount == 0)
+ {
+ sOriginalLevel = mOldLevel;
+ }
+ sGuardCount++;
Logging::SetGlobalLevel(newLevel);
}
~Guard()
{
+ sGuardCount--;
Logging::SetGlobalLevel(mOldLevel);
}
+
+ static bool IsActive() { return (sGuardCount > 0); }
+ static Log::Level GetOriginalLevel() { return sOriginalLevel; }
+ static bool IsGuardingFrom(Log::Level originalLevel)
+ {
+ return IsActive() &&
+ (int)sOriginalLevel >= (int)originalLevel;
+ }
};
class Tagger