Changeset 3074


Ignore:
Timestamp:
23/01/2012 01:32:08 (4 months ago)
Author:
chris
Message:

Allow overriding Logging::Guard to dump stack backtraces as well.

Location:
box/trunk/lib/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/Box.h

    r3073 r3074  
    1717 
    1818#include "BoxPlatform.h" 
     19 
     20#include <memory> 
    1921 
    2022// uncomment this line to enable full memory leak finding on all 
     
    105107        { \ 
    106108                if(!HideExceptionMessageGuard::ExceptionsHidden() \ 
    107                         || Logging::IsEnabled(Log::EVERYTHING)) \ 
     109                        || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \ 
    108110                { \ 
     111                        std::auto_ptr<Logging::Guard> guard; \ 
     112                        \ 
     113                        if(Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \ 
     114                        { \ 
     115                                guard.reset(new Logging::Guard(Log::EVERYTHING)); \ 
     116                        } \ 
     117                        \ 
    109118                        OPTIONAL_DO_BACKTRACE \ 
    110119                        BOX_WARNING("Exception thrown: " \ 
     
    120129                _box_throw_line << message; \ 
    121130                if(!HideExceptionMessageGuard::ExceptionsHidden() \ 
    122                         || Logging::IsEnabled(Log::EVERYTHING)) \ 
     131                        || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \ 
    123132                { \ 
     133                        std::auto_ptr<Logging::Guard> guard; \ 
     134                        \ 
     135                        if(Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \ 
     136                        { \ 
     137                                guard.reset(new Logging::Guard(Log::EVERYTHING)); \ 
     138                        } \ 
     139                        \ 
    124140                        OPTIONAL_DO_BACKTRACE \ 
    125141                        BOX_WARNING("Exception thrown: " \ 
  • box/trunk/lib/common/Logging.cpp

    r3021 r3074  
    4646Logging     Logging::sGlobalLogging; //automatic initialisation 
    4747std::string Logging::sProgramName; 
     48 
     49int Logging::Guard::sGuardCount = 0; 
     50Log::Level Logging::Guard::sOriginalLevel = Log::INVALID; 
    4851 
    4952Logging::Logging() 
  • box/trunk/lib/common/Logging.h

    r3064 r3074  
    304304                private: 
    305305                Log::Level mOldLevel; 
     306                static int sGuardCount; 
     307                static Log::Level sOriginalLevel; 
    306308 
    307309                public: 
     
    309311                { 
    310312                        mOldLevel = Logging::GetGlobalLevel(); 
     313                        if(sGuardCount == 0) 
     314                        { 
     315                                sOriginalLevel = mOldLevel; 
     316                        } 
     317                        sGuardCount++; 
    311318                        Logging::SetGlobalLevel(newLevel); 
    312319                } 
    313320                ~Guard() 
    314321                { 
     322                        sGuardCount--; 
    315323                        Logging::SetGlobalLevel(mOldLevel); 
     324                } 
     325 
     326                static bool IsActive() { return (sGuardCount > 0); } 
     327                static Log::Level GetOriginalLevel() { return sOriginalLevel; } 
     328                static bool IsGuardingFrom(Log::Level originalLevel) 
     329                { 
     330                        return IsActive() && 
     331                                (int)sOriginalLevel >= (int)originalLevel; 
    316332                } 
    317333        }; 
Note: See TracChangeset for help on using the changeset viewer.