log4cpp 1.1
|
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 #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 throw(std::invalid_argument); 00123 00128 virtual Priority::Value getPriority() const throw(); 00129 00138 virtual Priority::Value getChainedPriority() const throw(); 00139 00146 virtual bool isPriorityEnabled(Priority::Value priority) const throw(); 00147 00155 virtual void addAppender(Appender* appender) 00156 throw(std::invalid_argument); 00157 00164 virtual void addAppender(Appender& appender); 00165 00174 inline void setAppender(Appender* appender) { 00175 if (appender) { 00176 addAppender(appender); 00177 } else { 00178 removeAllAppenders(); 00179 } 00180 }; 00181 00188 inline void setAppender(Appender& appender) { 00189 addAppender(appender); 00190 }; 00191 00198 virtual Appender* getAppender() const; 00199 00206 virtual Appender* getAppender(const std::string& name) const; 00207 00213 virtual AppenderSet getAllAppenders() const; 00214 00218 virtual void removeAllAppenders(); 00219 00224 virtual void removeAppender(Appender* appender); 00225 00232 virtual bool ownsAppender() const throw() { 00233 return ownsAppender(getAppender()); 00234 }; 00235 00241 virtual bool ownsAppender(Appender* appender) const throw(); 00242 00254 virtual void callAppenders(const LoggingEvent& event) throw(); 00255 00259 virtual void setAdditivity(bool additivity); 00260 00264 virtual bool getAdditivity() const throw(); 00265 00271 virtual Category* getParent() throw(); 00272 00278 virtual const Category* getParent() const throw(); 00279 00287 virtual void log(Priority::Value priority, const char* stringFormat, 00288 ...) throw(); 00289 00295 virtual void log(Priority::Value priority, 00296 const std::string& message) throw(); 00297 00306 virtual void logva(Priority::Value priority, 00307 const char* stringFormat, 00308 va_list va) throw(); 00309 00316 void debug(const char* stringFormat, ...) throw(); 00317 00322 void debug(const std::string& message) throw(); 00323 00328 inline bool isDebugEnabled() const throw() { 00329 return isPriorityEnabled(Priority::DEBUG); 00330 }; 00331 00336 inline CategoryStream debugStream() { 00337 return getStream(Priority::DEBUG); 00338 } 00339 00346 void info(const char* stringFormat, ...) throw(); 00347 00352 void info(const std::string& message) throw(); 00353 00358 inline bool isInfoEnabled() const throw() { 00359 return isPriorityEnabled(Priority::INFO); 00360 }; 00361 00366 inline CategoryStream infoStream() { 00367 return getStream(Priority::INFO); 00368 } 00369 00376 void notice(const char* stringFormat, ...) throw(); 00377 00382 void notice(const std::string& message) throw(); 00383 00388 inline bool isNoticeEnabled() const throw() { 00389 return isPriorityEnabled(Priority::NOTICE); 00390 }; 00391 00396 inline CategoryStream noticeStream() { 00397 return getStream(Priority::NOTICE); 00398 } 00399 00406 void warn(const char* stringFormat, ...) throw(); 00407 00412 void warn(const std::string& message) throw(); 00413 00418 inline bool isWarnEnabled() const throw() { 00419 return isPriorityEnabled(Priority::WARN); 00420 }; 00421 00426 inline CategoryStream warnStream() { 00427 return getStream(Priority::WARN); 00428 }; 00429 00436 void error(const char* stringFormat, ...) throw(); 00437 00442 void error(const std::string& message) throw(); 00443 00448 inline bool isErrorEnabled() const throw() { 00449 return isPriorityEnabled(Priority::ERROR); 00450 }; 00451 00456 inline CategoryStream errorStream() { 00457 return getStream(Priority::ERROR); 00458 }; 00459 00466 void crit(const char* stringFormat, ...) throw(); 00467 00472 void crit(const std::string& message) throw(); 00473 00478 inline bool isCritEnabled() const throw() { 00479 return isPriorityEnabled(Priority::CRIT); 00480 }; 00481 00486 inline CategoryStream critStream() { 00487 return getStream(Priority::CRIT); 00488 }; 00489 00496 void alert(const char* stringFormat, ...) throw(); 00497 00502 void alert(const std::string& message) throw(); 00503 00508 inline bool isAlertEnabled() const throw() { 00509 return isPriorityEnabled(Priority::ALERT); 00510 }; 00511 00516 inline CategoryStream alertStream() throw() { 00517 return getStream(Priority::ALERT); 00518 }; 00519 00526 void emerg(const char* stringFormat, ...) throw(); 00527 00532 void emerg(const std::string& message) throw(); 00533 00538 inline bool isEmergEnabled() const throw() { 00539 return isPriorityEnabled(Priority::EMERG); 00540 }; 00541 00546 inline CategoryStream emergStream() { 00547 return getStream(Priority::EMERG); 00548 }; 00549 00558 void fatal(const char* stringFormat, ...) throw(); 00559 00566 void fatal(const std::string& message) throw(); 00567 00574 inline bool isFatalEnabled() const throw() { 00575 return isPriorityEnabled(Priority::FATAL); 00576 }; 00577 00584 inline CategoryStream fatalStream() { 00585 return getStream(Priority::FATAL); 00586 }; 00587 00593 virtual CategoryStream getStream(Priority::Value priority); 00594 00600 virtual CategoryStream operator<<(Priority::Value priority); 00601 00602 protected: 00603 00612 Category(const std::string& name, Category* parent, 00613 Priority::Value priority = Priority::NOTSET); 00614 00615 virtual void _logUnconditionally(Priority::Value priority, 00616 const char* format, 00617 va_list arguments) throw(); 00618 00624 virtual void _logUnconditionally2(Priority::Value priority, 00625 const std::string& message) throw(); 00626 00627 private: 00628 00629 /* prevent copying and assignment */ 00630 Category(const Category& other); 00631 Category& operator=(const Category& other); 00632 00634 const std::string _name; 00635 00640 Category* _parent; 00641 00645 volatile Priority::Value _priority; 00646 00647 typedef std::map<Appender *, bool> OwnsAppenderMap; 00648 00655 virtual bool ownsAppender(Appender* appender, 00656 OwnsAppenderMap::iterator& i2) throw(); 00657 00658 AppenderSet _appender; 00659 mutable threading::Mutex _appenderSetMutex; 00660 00666 OwnsAppenderMap _ownsAppender; 00667 00672 volatile bool _isAdditive; 00673 00674 }; 00675 00676 } 00677 #endif // _LOG4CPP_CATEGORY_HH