Changeset 2279


Ignore:
Timestamp:
13/09/2008 16:11:35 (3 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.

Location:
box/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/infrastructure/buildenv-testmain-template.cpp

    r2166 r2279  
    258258                        case 't': 
    259259                        { 
    260                                 Console::SetTag(optarg); 
     260                                Logging::SetProgramName(optarg); 
     261                                Console::SetShowTag(true); 
    261262                        } 
    262263                        break; 
  • box/trunk/lib/common/Logging.cpp

    r2231 r2279  
    3636Log::Level  Logging::sGlobalLevel = Log::EVERYTHING; 
    3737Logging     Logging::sGlobalLogging; //automatic initialisation 
     38std::string Logging::sProgramName; 
    3839 
    3940Logging::Logging() 
     
    207208void Logging::SetProgramName(const std::string& rProgramName) 
    208209{ 
     210        sProgramName = rProgramName; 
     211 
    209212        for (std::vector<Logger*>::iterator i = sLoggers.begin(); 
    210213                i != sLoggers.end(); i++) 
     
    231234std::string Console::sTag; 
    232235 
    233 void Console::SetTag(const std::string& rTag) 
    234 { 
    235         sTag = rTag; 
    236         sShowTag = true; 
     236void Console::SetProgramName(const std::string& rProgramName) 
     237{ 
     238        sTag = rProgramName; 
     239} 
     240 
     241void Console::SetShowTag(bool enabled) 
     242{ 
     243        sShowTag = enabled; 
    237244} 
    238245 
  • 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 
  • box/trunk/lib/server/Daemon.cpp

    r2252 r2279  
    236236                case 't': 
    237237                { 
    238                         Console::SetTag(optarg); 
     238                        Logging::SetProgramName(optarg); 
     239                        Console::SetShowTag(true); 
    239240                } 
    240241                break; 
Note: See TracChangeset for help on using the changeset viewer.