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

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/Export.hh"
00015 #include "log4cpp/OstringStream.hh"
00016 #include "log4cpp/Appender.hh"
00017 #include "log4cpp/LoggingEvent.hh"
00018 #include "log4cpp/Priority.hh"
00019 #include "log4cpp/CategoryStream.hh"
00020 
00021 #include <map>
00022 #include <set>
00023 #include <stdarg.h>
00024 
00025 namespace log4cpp {
00026 
00032     class LOG4CPP_EXPORT Category {
00033         friend class HierarchyMaintainer;
00034 
00035         public:
00036 
00048         static Category& getRoot();
00049 
00054         static void setRootPriority(Priority::Value priority);
00055 
00060         static Priority::Value getRootPriority() throw();
00061 
00069         static Category& getInstance(const std::string& name);
00070             
00076         static Category* exists(const std::string& name);
00077 
00088         static std::set<Category*>* getCurrentCategories();
00089 
00093         static void shutdown();
00094 
00098         virtual ~Category();
00099         
00104         virtual const std::string& getName() const throw(); 
00105         
00111         virtual void setPriority(Priority::Value priority);
00112 
00117         virtual Priority::Value getPriority() const throw();
00118 
00127         virtual Priority::Value getChainedPriority() const throw();
00128 
00135         virtual bool isPriorityEnabled(Priority::Value priority) const throw();
00136         
00144         virtual void addAppender(Appender* appender);
00145 
00152         virtual void addAppender(Appender& appender);
00153 
00162         inline void setAppender(Appender* appender) {
00163             if (appender) {
00164                 addAppender(appender);
00165             } else {
00166                 removeAllAppenders();
00167             }
00168         };
00169 
00176         inline void setAppender(Appender& appender) {
00177             addAppender(appender);
00178         };
00179 
00186         virtual Appender* getAppender() const;
00187 
00194         virtual Appender* getAppender(const std::string& name) const;
00195 
00199         virtual void removeAllAppenders();
00200 
00205         virtual void removeAppender(Appender* appender);
00206 
00213         inline bool ownsAppender() const throw() {
00214             return ownsAppender(getAppender());
00215         };
00216 
00222         virtual bool ownsAppender(Appender* appender) const throw();
00223 
00235         virtual void callAppenders(const LoggingEvent& event) throw();
00236         
00240         virtual void setAdditivity(bool additivity);
00241 
00245         virtual bool getAdditivity() const throw();
00246 
00252         virtual Category* getParent() throw();
00253 
00259         virtual const Category* getParent() const throw();
00260 
00268         virtual void log(Priority::Value priority, const char* stringFormat,
00269                          ...) throw();
00270 
00276         virtual void log(Priority::Value priority, 
00277                          const std::string& message) throw();
00278         
00285         virtual void logva(Priority::Value priority, 
00286                            const char* stringFormat,
00287                            va_list va) throw();
00288         
00295         void debug(const char* stringFormat, ...) throw();
00296 
00301         void debug(const std::string& message) throw();
00302 
00307         inline bool isDebugEnabled() const throw() { 
00308             return isPriorityEnabled(Priority::DEBUG);
00309         };
00310         
00315         inline CategoryStream debugStream() {
00316             return getStream(Priority::DEBUG);
00317         }
00318 
00325         void info(const char* stringFormat, ...) throw();
00326 
00331         void info(const std::string& message) throw();
00332 
00337         inline bool isInfoEnabled() const throw() { 
00338             return isPriorityEnabled(Priority::INFO);
00339         };
00340 
00345         inline CategoryStream infoStream() {
00346             return getStream(Priority::INFO);
00347         }
00348         
00355         void notice(const char* stringFormat, ...) throw();
00356 
00361         void notice(const std::string& message) throw();
00362 
00367         inline bool isNoticeEnabled() const throw() { 
00368             return isPriorityEnabled(Priority::NOTICE);
00369         };
00370 
00375         inline CategoryStream noticeStream() {
00376             return getStream(Priority::NOTICE);
00377         }
00378         
00385         void warn(const char* stringFormat, ...) throw();
00386 
00391         void warn(const std::string& message) throw();
00392 
00397         inline bool isWarnEnabled() const throw() { 
00398             return isPriorityEnabled(Priority::WARN);
00399         };
00400 
00405         inline CategoryStream warnStream() {
00406             return getStream(Priority::WARN);
00407         };
00408         
00415         void error(const char* stringFormat, ...) throw();
00416 
00421         void error(const std::string& message) throw();
00422 
00427         inline bool isErrorEnabled() const throw() { 
00428             return isPriorityEnabled(Priority::ERROR);
00429         };
00430         
00435         inline CategoryStream errorStream() {
00436             return getStream(Priority::ERROR);
00437         };
00438 
00445         void crit(const char* stringFormat, ...) throw();
00446 
00451         void crit(const std::string& message) throw();
00452 
00457         inline bool isCritEnabled() const throw() { 
00458             return isPriorityEnabled(Priority::CRIT);
00459         };
00460         
00465         inline CategoryStream critStream() {
00466             return getStream(Priority::CRIT);
00467         };
00468         
00475         void alert(const char* stringFormat, ...) throw();
00476 
00481         void alert(const std::string& message) throw();
00482 
00487         inline bool isAlertEnabled() const throw() { 
00488             return isPriorityEnabled(Priority::ALERT);
00489         };
00490         
00495         inline CategoryStream alertStream() throw() {
00496             return getStream(Priority::ALERT);
00497         };
00498 
00505         void emerg(const char* stringFormat, ...) throw();
00506 
00511         void emerg(const std::string& message) throw();
00512 
00517         inline bool isEmergEnabled() const throw() { 
00518             return isPriorityEnabled(Priority::EMERG);
00519         };
00520         
00525         inline CategoryStream emergStream() {
00526             return getStream(Priority::EMERG);
00527         };
00528 
00537         void fatal(const char* stringFormat, ...) throw();
00538 
00545         void fatal(const std::string& message) throw();
00546 
00553         inline bool isFatalEnabled() const throw() { 
00554             return isPriorityEnabled(Priority::FATAL);
00555         };
00556         
00563         inline CategoryStream fatalStream() {
00564             return getStream(Priority::FATAL);
00565         };
00566 
00572         virtual CategoryStream getStream(Priority::Value priority);
00573 
00579         virtual CategoryStream operator<<(Priority::Value priority);
00580 
00581         protected:
00582 
00591         Category(const std::string& name, Category* parent, 
00592                                 Priority::Value priority = Priority::NOTSET);
00593         
00594         virtual void _logUnconditionally(Priority::Value priority, 
00595                                          const char* format, 
00596                                          va_list arguments) throw();
00597         
00603         virtual void _logUnconditionally2(Priority::Value priority, 
00604                                           const std::string& message) throw();
00605 
00606         private:
00607 
00608         /* prevent copying and assignment */
00609         Category(const Category& other);
00610         Category& operator=(const Category& other);
00611 
00613         const std::string _name;
00614 
00619         Category* _parent;
00620 
00624         Priority::Value _priority;
00625 
00626         typedef std::set<Appender *> AppenderSet;
00627         typedef std::map<Appender *, bool> OwnsAppenderMap;
00628 
00635         virtual bool ownsAppender(Appender* appender, 
00636                                   OwnsAppenderMap::iterator& i2) throw();
00637 
00638         AppenderSet _appender;
00639 
00645          OwnsAppenderMap _ownsAppender;
00646 
00651          bool _isAdditive;
00652 
00653     };
00654 
00655 }
00656 #endif // _LOG4CPP_CATEGORY_HH

Generated at Mon Jan 28 01:40:21 2002 for log4cpp by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001