00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _LOG4CPP_CATEGORY_HH
00011 #define _LOG4CPP_CATEGORY_HH
00012
00013 #include <map>
00014 #include <set>
00015 #include <stdarg.h>
00016 #include "log4cpp/Export.hh"
00017 #include "log4cpp/OstringStream.hh"
00018 #include "log4cpp/Appender.hh"
00019 #include "log4cpp/LoggingEvent.hh"
00020 #include "log4cpp/Priority.hh"
00021
00022 namespace log4cpp {
00023
00024 class LOG4CPP_EXPORT Category;
00025
00030 class LOG4CPP_EXPORT CategoryStream {
00031 public:
00032
00037 typedef enum {
00038 ENDLINE
00039 } Separator;
00040
00047 CategoryStream(Category& category, Priority::Value priority);
00048
00052 ~CategoryStream();
00053
00058 inline Category& getCategory() const { return _category; };
00059
00064 inline Priority::Value getPriority() const throw() {
00065 return _priority;
00066 };
00067
00075 CategoryStream& operator<<(Separator separator);
00076
00081 void flush();
00082
00088 template<typename T> CategoryStream& operator<<(const T& t) {
00089 if (getPriority() != Priority::NOTSET) {
00090 if (!_buffer) {
00091 if (!(_buffer = new OstringStream)) {
00092
00093 }
00094 }
00095 (*_buffer) << t;
00096 }
00097 return *this;
00098 }
00099
00100 private:
00101 Category& _category;
00102 Priority::Value _priority;
00103 OstringStream* _buffer;
00104 };
00105
00111 class LOG4CPP_EXPORT Category {
00112 friend class HierarchyMaintainer;
00113
00114 public:
00115
00127 static Category& getRoot();
00128
00133 static void setRootPriority(Priority::Value priority);
00134
00139 static Priority::Value getRootPriority() throw();
00140
00148 static Category& getInstance(const std::string& name);
00149
00160 static std::set<Category*>* getCurrentCategories();
00161
00165 static void shutdown();
00166
00170 virtual ~Category();
00171
00176 virtual const std::string& getName() const throw();
00177
00183 virtual void setPriority(Priority::Value priority);
00184
00189 virtual Priority::Value getPriority() const throw();
00190
00199 virtual Priority::Value getChainedPriority() const throw();
00200
00207 virtual bool isPriorityEnabled(Priority::Value priority) const throw();
00208
00214 virtual void setAppender(Appender* appender);
00215
00221 virtual void setAppender(Appender& appender);
00222
00228 virtual Appender* getAppender() const;
00229
00234 virtual void removeAllAppenders();
00235
00240 virtual bool ownsAppender() const throw();
00241
00253 virtual void callAppenders(const LoggingEvent& event) throw();
00254
00258 virtual void setAdditivity(bool additivity);
00259
00263 virtual bool getAdditivity() const throw();
00264
00270 virtual Category* getParent() throw();
00271
00277 virtual const Category* getParent() const throw();
00278
00286 virtual void log(Priority::Value priority, const char* stringFormat,
00287 ...) throw();
00288
00294 virtual void log(Priority::Value priority,
00295 const std::string& message) throw();
00296
00303 void debug(const char* stringFormat, ...) throw();
00304
00309 void debug(const std::string& message) throw();
00310
00315 inline bool isDebugEnabled() const throw() {
00316 return isPriorityEnabled(Priority::DEBUG);
00317 };
00318
00323 inline CategoryStream debugStream() {
00324 return getStream(Priority::DEBUG);
00325 }
00326
00333 void info(const char* stringFormat, ...) throw();
00334
00339 void info(const std::string& message) throw();
00340
00345 inline bool isInfoEnabled() const throw() {
00346 return isPriorityEnabled(Priority::INFO);
00347 };
00348
00353 inline CategoryStream infoStream() {
00354 return getStream(Priority::INFO);
00355 }
00356
00363 void notice(const char* stringFormat, ...) throw();
00364
00369 void notice(const std::string& message) throw();
00370
00375 inline bool isNoticeEnabled() const throw() {
00376 return isPriorityEnabled(Priority::NOTICE);
00377 };
00378
00383 inline CategoryStream noticeStream() {
00384 return getStream(Priority::NOTICE);
00385 }
00386
00393 void warn(const char* stringFormat, ...) throw();
00394
00399 void warn(const std::string& message) throw();
00400
00405 inline bool isWarnEnabled() const throw() {
00406 return isPriorityEnabled(Priority::WARN);
00407 };
00408
00413 inline CategoryStream warnStream() {
00414 return getStream(Priority::WARN);
00415 }
00416
00423 void error(const char* stringFormat, ...) throw();
00424
00429 void error(const std::string& message) throw();
00430
00435 inline bool isErrorEnabled() const throw() {
00436 return isPriorityEnabled(Priority::ERROR);
00437 };
00438
00443 inline CategoryStream errorStream() {
00444 return getStream(Priority::ERROR);
00445 }
00446
00453 void crit(const char* stringFormat, ...) throw();
00454
00459 void crit(const std::string& message) throw();
00460
00465 inline bool isCritEnabled() const throw() {
00466 return isPriorityEnabled(Priority::CRIT);
00467 };
00468
00473 inline CategoryStream critStream() {
00474 return getStream(Priority::CRIT);
00475 }
00476
00483 void alert(const char* stringFormat, ...) throw();
00484
00489 void alert(const std::string& message) throw();
00490
00495 inline bool isAlertEnabled() const throw() {
00496 return isPriorityEnabled(Priority::ALERT);
00497 };
00498
00503 inline CategoryStream alertStream() throw() {
00504 return getStream(Priority::ALERT);
00505 }
00506
00513 void emerg(const char* stringFormat, ...) throw();
00514
00519 void emerg(const std::string& message) throw();
00520
00525 inline bool isEmergEnabled() const throw() {
00526 return isPriorityEnabled(Priority::EMERG);
00527 };
00528
00533 inline CategoryStream emergStream() {
00534 return getStream(Priority::EMERG);
00535 }
00536
00542 virtual CategoryStream getStream(Priority::Value priority);
00543
00549 virtual CategoryStream operator<<(Priority::Value priority);
00550
00551 protected:
00552
00561 Category(const std::string& name, Category* parent,
00562 Priority::Value priority = Priority::NOTSET);
00563
00564 virtual void _logUnconditionally(Priority::Value priority,
00565 const char* format,
00566 va_list arguments) throw();
00567
00573 virtual void _logUnconditionally2(Priority::Value priority,
00574 const std::string& message) throw();
00575
00576 private:
00577
00579 const std::string _name;
00580
00585 Category* _parent;
00586
00590 Priority::Value _priority;
00591
00597 Appender* _appender;
00598
00603 bool _ownsAppender;
00604
00609 bool _isAdditive;
00610
00611 };
00612
00613 }
00614 #endif // _LOG4CPP_CATEGORY_HH