Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Category.hh

Go to the documentation of this file.
00001 /*
00002  * Category.hh
00003  *
00004  * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
00005  * Copyright 2000, Bastiaan Bakker. All rights reserved.
00006  *
00007  * See the COPYING file for the terms of usage and distribution.
00008  */
00009 
00010 #ifndef _LOG4CPP_CATEGORY_HH
00011 #define _LOG4CPP_CATEGORY_HH
00012 
00013 #include <log4cpp/Portability.hh>
00014 #include <log4cpp/Appender.hh>
00015 #include <log4cpp/LoggingEvent.hh>
00016 #include <log4cpp/Priority.hh>
00017 #include <log4cpp/CategoryStream.hh>
00018 #include <log4cpp/threading/Threading.hh>
00019 
00020 #include <map>
00021 #include <vector>
00022 #include <cstdarg>
00023 #include <stdexcept>
00024 
00025 namespace log4cpp {
00026 
00032     class LOG4CPP_EXPORT Category {
00033         friend class HierarchyMaintainer;
00034 
00035         public:
00047         static Category& getRoot();
00048 
00053         static void setRootPriority(Priority::Value priority);
00054 
00059         static Priority::Value getRootPriority() throw();
00060 
00068         static Category& getInstance(const std::string& name);
00069             
00075         static Category* exists(const std::string& name);
00076 
00089         static std::vector<Category*>* getCurrentCategories();
00090 
00094         static void shutdown();
00095 
00099         virtual ~Category();
00100         
00105         virtual const std::string& getName() const throw(); 
00106         
00114         virtual void setPriority(Priority::Value priority) 
00115         throw(std::invalid_argument);
00116 
00121         virtual Priority::Value getPriority() const throw();
00122 
00131         virtual Priority::Value getChainedPriority() const throw();
00132 
00139         virtual bool isPriorityEnabled(Priority::Value priority) const throw();
00140         
00148         virtual void addAppender(Appender* appender) 
00149         throw(std::invalid_argument);
00150 
00157         virtual void addAppender(Appender& appender);
00158 
00167         inline void setAppender(Appender* appender) {
00168             if (appender) {
00169                 addAppender(appender);
00170             } else {
00171                 removeAllAppenders();
00172             }
00173         };
00174 
00181         inline void setAppender(Appender& appender) {
00182             addAppender(appender);
00183         };
00184 
00191         virtual Appender* getAppender() const;
00192 
00199         virtual Appender* getAppender(const std::string& name) const;
00200 
00206         virtual AppenderSet getAllAppenders() const;
00207 
00211         virtual void removeAllAppenders();
00212 
00217         virtual void removeAppender(Appender* appender);
00218 
00225         inline bool ownsAppender() const throw() {
00226             return ownsAppender(getAppender());
00227         };
00228 
00234         virtual bool ownsAppender(Appender* appender) const throw();
00235 
00247         virtual void callAppenders(const LoggingEvent& event) throw();
00248         
00252         virtual void setAdditivity(bool additivity);
00253 
00257         virtual bool getAdditivity() const throw();
00258 
00264         virtual Category* getParent() throw();
00265 
00271         virtual const Category* getParent() const throw();
00272 
00280         virtual void log(Priority::Value priority, const char* stringFormat,
00281                          ...) throw();
00282 
00288         virtual void log(Priority::Value priority, 
00289                          const std::string& message) throw();
00290         
00299         virtual void logva(Priority::Value priority, 
00300                            const char* stringFormat,
00301                            va_list va) throw();
00302         
00309         void debug(const char* stringFormat, ...) throw();
00310 
00315         void debug(const std::string& message) throw();
00316 
00321         inline bool isDebugEnabled() const throw() { 
00322             return isPriorityEnabled(Priority::DEBUG);
00323         };
00324         
00329         inline CategoryStream debugStream() {
00330             return getStream(Priority::DEBUG);
00331         }
00332 
00339         void info(const char* stringFormat, ...) throw();
00340 
00345         void info(const std::string& message) throw();
00346 
00351         inline bool isInfoEnabled() const throw() { 
00352             return isPriorityEnabled(Priority::INFO);
00353         };
00354 
00359         inline CategoryStream infoStream() {
00360             return getStream(Priority::INFO);
00361         }
00362         
00369         void notice(const char* stringFormat, ...) throw();
00370 
00375         void notice(const std::string& message) throw();
00376 
00381         inline bool isNoticeEnabled() const throw() { 
00382             return isPriorityEnabled(Priority::NOTICE);
00383         };
00384 
00389         inline CategoryStream noticeStream() {
00390             return getStream(Priority::NOTICE);
00391         }
00392         
00399         void warn(const char* stringFormat, ...) throw();
00400 
00405         void warn(const std::string& message) throw();
00406 
00411         inline bool isWarnEnabled() const throw() { 
00412             return isPriorityEnabled(Priority::WARN);
00413         };
00414 
00419         inline CategoryStream warnStream() {
00420             return getStream(Priority::WARN);
00421         };
00422         
00429         void error(const char* stringFormat, ...) throw();
00430 
00435         void error(const std::string& message) throw();
00436 
00441         inline bool isErrorEnabled() const throw() { 
00442             return isPriorityEnabled(Priority::ERROR);
00443         };
00444         
00449         inline CategoryStream errorStream() {
00450             return getStream(Priority::ERROR);
00451         };
00452 
00459         void crit(const char* stringFormat, ...) throw();
00460 
00465         void crit(const std::string& message) throw();
00466 
00471         inline bool isCritEnabled() const throw() { 
00472             return isPriorityEnabled(Priority::CRIT);
00473         };
00474         
00479         inline CategoryStream critStream() {
00480             return getStream(Priority::CRIT);
00481         };
00482         
00489         void alert(const char* stringFormat, ...) throw();
00490 
00495         void alert(const std::string& message) throw();
00496 
00501         inline bool isAlertEnabled() const throw() { 
00502             return isPriorityEnabled(Priority::ALERT);
00503         };
00504         
00509         inline CategoryStream alertStream() throw() {
00510             return getStream(Priority::ALERT);
00511         };
00512 
00519         void emerg(const char* stringFormat, ...) throw();
00520 
00525         void emerg(const std::string& message) throw();
00526 
00531         inline bool isEmergEnabled() const throw() { 
00532             return isPriorityEnabled(Priority::EMERG);
00533         };
00534         
00539         inline CategoryStream emergStream() {
00540             return getStream(Priority::EMERG);
00541         };
00542 
00551         void fatal(const char* stringFormat, ...) throw();
00552 
00559         void fatal(const std::string& message) throw();
00560 
00567         inline bool isFatalEnabled() const throw() { 
00568             return isPriorityEnabled(Priority::FATAL);
00569         };
00570         
00577         inline CategoryStream fatalStream() {
00578             return getStream(Priority::FATAL);
00579         };
00580 
00586         virtual CategoryStream getStream(Priority::Value priority);
00587 
00593         virtual CategoryStream operator<<(Priority::Value priority);
00594 
00595         protected:
00596 
00605         Category(const std::string& name, Category* parent, 
00606                                 Priority::Value priority = Priority::NOTSET);
00607         
00608         virtual void _logUnconditionally(Priority::Value priority, 
00609                                          const char* format, 
00610                                          va_list arguments) throw();
00611         
00617         virtual void _logUnconditionally2(Priority::Value priority, 
00618                                           const std::string& message) throw();
00619 
00620         private:
00621 
00622         /* prevent copying and assignment */
00623         Category(const Category& other);
00624         Category& operator=(const Category& other);
00625 
00627         const std::string _name;
00628 
00633         Category* _parent;
00634 
00638         volatile Priority::Value _priority;
00639 
00640         typedef std::map<Appender *, bool> OwnsAppenderMap;
00641 
00648         virtual bool ownsAppender(Appender* appender, 
00649                                   OwnsAppenderMap::iterator& i2) throw();
00650 
00651         AppenderSet _appender;
00652         mutable threading::Mutex _appenderSetMutex;
00653 
00659         OwnsAppenderMap _ownsAppender;
00660 
00665         volatile bool _isAdditive;
00666 
00667     };
00668 
00669 }
00670 #endif // _LOG4CPP_CATEGORY_HH

Generated on Mon Oct 28 23:41:43 2002 for log4cpp by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002