00001
00002
00003
00004
00005
00006
00007
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 #include <log4cpp/convenience.h>
00020
00021 #include <map>
00022 #include <vector>
00023 #include <cstdarg>
00024 #include <stdexcept>
00025
00026 namespace log4cpp {
00027
00033 class LOG4CPP_EXPORT Category {
00034 friend class HierarchyMaintainer;
00035
00036 public:
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
00090 static std::vector<Category*>* getCurrentCategories();
00091
00095 static void shutdown();
00096
00101 static void shutdownForced();
00102
00106 virtual ~Category();
00107
00112 virtual const std::string& getName() const throw();
00113
00121 virtual void setPriority(Priority::Value priority);
00122
00127 virtual Priority::Value getPriority() const throw();
00128
00137 virtual Priority::Value getChainedPriority() const throw();
00138
00145 virtual bool isPriorityEnabled(Priority::Value priority) const throw();
00146
00154 virtual void addAppender(Appender* appender);
00155
00162 virtual void addAppender(Appender& appender);
00163
00172 inline void setAppender(Appender* appender) {
00173 if (appender) {
00174 addAppender(appender);
00175 } else {
00176 removeAllAppenders();
00177 }
00178 };
00179
00186 inline void setAppender(Appender& appender) {
00187 addAppender(appender);
00188 };
00189
00196 virtual Appender* getAppender() const;
00197
00204 virtual Appender* getAppender(const std::string& name) const;
00205
00211 virtual AppenderSet getAllAppenders() const;
00212
00216 virtual void removeAllAppenders();
00217
00222 virtual void removeAppender(Appender* appender);
00223
00230 virtual bool ownsAppender() const throw() {
00231 return ownsAppender(getAppender());
00232 };
00233
00239 virtual bool ownsAppender(Appender* appender) const throw();
00240
00252 virtual void callAppenders(const LoggingEvent& event) throw();
00253
00257 virtual void setAdditivity(bool additivity);
00258
00262 virtual bool getAdditivity() const throw();
00263
00269 virtual Category* getParent() throw();
00270
00276 virtual const Category* getParent() const throw();
00277
00285 virtual void log(Priority::Value priority, const char* stringFormat,
00286 ...) throw();
00287
00293 virtual void log(Priority::Value priority,
00294 const std::string& message) throw();
00295
00304 virtual void logva(Priority::Value priority,
00305 const char* stringFormat,
00306 va_list va) throw();
00307
00314 void debug(const char* stringFormat, ...) throw();
00315
00320 void debug(const std::string& message) throw();
00321
00326 inline bool isDebugEnabled() const throw() {
00327 return isPriorityEnabled(Priority::DEBUG);
00328 };
00329
00334 inline CategoryStream debugStream() {
00335 return getStream(Priority::DEBUG);
00336 }
00337
00344 void info(const char* stringFormat, ...) throw();
00345
00350 void info(const std::string& message) throw();
00351
00356 inline bool isInfoEnabled() const throw() {
00357 return isPriorityEnabled(Priority::INFO);
00358 };
00359
00364 inline CategoryStream infoStream() {
00365 return getStream(Priority::INFO);
00366 }
00367
00374 void notice(const char* stringFormat, ...) throw();
00375
00380 void notice(const std::string& message) throw();
00381
00386 inline bool isNoticeEnabled() const throw() {
00387 return isPriorityEnabled(Priority::NOTICE);
00388 };
00389
00394 inline CategoryStream noticeStream() {
00395 return getStream(Priority::NOTICE);
00396 }
00397
00404 void warn(const char* stringFormat, ...) throw();
00405
00410 void warn(const std::string& message) throw();
00411
00416 inline bool isWarnEnabled() const throw() {
00417 return isPriorityEnabled(Priority::WARN);
00418 };
00419
00424 inline CategoryStream warnStream() {
00425 return getStream(Priority::WARN);
00426 };
00427
00434 void error(const char* stringFormat, ...) throw();
00435
00440 void error(const std::string& message) throw();
00441
00446 inline bool isErrorEnabled() const throw() {
00447 return isPriorityEnabled(Priority::ERROR);
00448 };
00449
00454 inline CategoryStream errorStream() {
00455 return getStream(Priority::ERROR);
00456 };
00457
00464 void crit(const char* stringFormat, ...) throw();
00465
00470 void crit(const std::string& message) throw();
00471
00476 inline bool isCritEnabled() const throw() {
00477 return isPriorityEnabled(Priority::CRIT);
00478 };
00479
00484 inline CategoryStream critStream() {
00485 return getStream(Priority::CRIT);
00486 };
00487
00494 void alert(const char* stringFormat, ...) throw();
00495
00500 void alert(const std::string& message) throw();
00501
00506 inline bool isAlertEnabled() const throw() {
00507 return isPriorityEnabled(Priority::ALERT);
00508 };
00509
00514 inline CategoryStream alertStream() throw() {
00515 return getStream(Priority::ALERT);
00516 };
00517
00524 void emerg(const char* stringFormat, ...) throw();
00525
00530 void emerg(const std::string& message) throw();
00531
00536 inline bool isEmergEnabled() const throw() {
00537 return isPriorityEnabled(Priority::EMERG);
00538 };
00539
00544 inline CategoryStream emergStream() {
00545 return getStream(Priority::EMERG);
00546 };
00547
00556 void fatal(const char* stringFormat, ...) throw();
00557
00564 void fatal(const std::string& message) throw();
00565
00572 inline bool isFatalEnabled() const throw() {
00573 return isPriorityEnabled(Priority::FATAL);
00574 };
00575
00582 inline CategoryStream fatalStream() {
00583 return getStream(Priority::FATAL);
00584 };
00585
00591 virtual CategoryStream getStream(Priority::Value priority);
00592
00598 virtual CategoryStream operator<<(Priority::Value priority);
00599
00600 protected:
00601
00610 Category(const std::string& name, Category* parent,
00611 Priority::Value priority = Priority::NOTSET);
00612
00613 virtual void _logUnconditionally(Priority::Value priority,
00614 const char* format,
00615 va_list arguments) throw();
00616
00622 virtual void _logUnconditionally2(Priority::Value priority,
00623 const std::string& message) throw();
00624
00625 private:
00626
00627
00628 Category(const Category& other);
00629 Category& operator=(const Category& other);
00630
00632 const std::string _name;
00633
00638 Category* _parent;
00639
00643 volatile Priority::Value _priority;
00644
00645 typedef std::map<Appender *, bool> OwnsAppenderMap;
00646
00653 virtual bool ownsAppender(Appender* appender,
00654 OwnsAppenderMap::iterator& i2) throw();
00655
00656 AppenderSet _appender;
00657 mutable threading::Mutex _appenderSetMutex;
00658
00664 OwnsAppenderMap _ownsAppender;
00665
00670 volatile bool _isAdditive;
00671
00672 };
00673
00674 }
00675 #endif // _LOG4CPP_CATEGORY_HH