[Box Backup-commit] COMMIT r3074 - box/trunk/lib/common
subversion at boxbackup.org
subversion at boxbackup.org
Mon Jan 23 01:32:09 GMT 2012
Author: chris
Date: 2012-01-23 01:32:08 +0000 (Mon, 23 Jan 2012)
New Revision: 3074
Modified:
box/trunk/lib/common/Box.h
box/trunk/lib/common/Logging.cpp
box/trunk/lib/common/Logging.h
Log:
Allow overriding Logging::Guard to dump stack backtraces as well.
Modified: box/trunk/lib/common/Box.h
===================================================================
--- box/trunk/lib/common/Box.h 2012-01-23 00:40:42 UTC (rev 3073)
+++ box/trunk/lib/common/Box.h 2012-01-23 01:32:08 UTC (rev 3074)
@@ -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 << \
Modified: box/trunk/lib/common/Logging.cpp
===================================================================
--- box/trunk/lib/common/Logging.cpp 2012-01-23 00:40:42 UTC (rev 3073)
+++ box/trunk/lib/common/Logging.cpp 2012-01-23 01:32:08 UTC (rev 3074)
@@ -46,6 +46,9 @@
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);
Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h 2012-01-23 00:40:42 UTC (rev 3073)
+++ box/trunk/lib/common/Logging.h 2012-01-23 01:32:08 UTC (rev 3074)
@@ -303,17 +303,33 @@
{
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
More information about the Boxbackup-commit
mailing list