Ignore:
Timestamp:
13/09/2008 16:11:35 (4 years ago)
Author:
chris
Message:

Unify program name and console logging tags.

Add a new class, Logging::Tagger, which can be used to temporarily
add information to the program name, such as the client ID in bbstored.

File:
1 edited

Legend:

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

    r2208 r2279  
    144144{ 
    145145        private: 
     146        static bool sShowTag; 
    146147        static bool sShowTime; 
    147148        static bool sShowTimeMicros; 
    148         static bool sShowTag; 
     149        static bool sShowPID; 
    149150        static std::string sTag; 
    150         static bool sShowPID; 
    151151 
    152152        public: 
     
    154154                int line, std::string& rMessage); 
    155155        virtual const char* GetType() { return "Console"; } 
    156         virtual void SetProgramName(const std::string& rProgramName) { } 
    157  
    158         static void SetTag(const std::string& rTag); 
     156        virtual void SetProgramName(const std::string& rProgramName); 
     157 
     158        static void SetShowTag(bool enabled); 
    159159        static void SetShowTime(bool enabled); 
    160160        static void SetShowTimeMicros(bool enabled); 
     
    207207        static Log::Level sGlobalLevel; 
    208208        static Logging    sGlobalLogging; 
     209        static std::string sProgramName; 
    209210         
    210211        public: 
     
    231232        } 
    232233        static void SetProgramName(const std::string& rProgramName); 
     234        static std::string GetProgramName() { return sProgramName; } 
    233235 
    234236        class Guard 
     
    248250                } 
    249251        }; 
     252 
     253        class Tagger 
     254        { 
     255                private: 
     256                std::string mOldTag; 
     257 
     258                public: 
     259                Tagger(const std::string& rTempTag) 
     260                { 
     261                        mOldTag = Logging::GetProgramName(); 
     262                        Logging::SetProgramName(mOldTag + " " + rTempTag); 
     263                } 
     264                ~Tagger() 
     265                { 
     266                        Logging::SetProgramName(mOldTag); 
     267                } 
     268        }; 
    250269}; 
    251270 
Note: See TracChangeset for help on using the changeset viewer.