log4cpp  1.1
Category.hh
Go to the documentation of this file.
1 /*
2  * Category.hh
3  *
4  * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5  * Copyright 2000, Bastiaan Bakker. All rights reserved.
6  *
7  * See the COPYING file for the terms of usage and distribution.
8  */
9 
10 #ifndef _LOG4CPP_CATEGORY_HH
11 #define _LOG4CPP_CATEGORY_HH
12 
13 #include <log4cpp/Portability.hh>
14 #include <log4cpp/Appender.hh>
15 #include <log4cpp/LoggingEvent.hh>
16 #include <log4cpp/Priority.hh>
19 #include <log4cpp/convenience.h>
20 
21 #include <map>
22 #include <vector>
23 #include <cstdarg>
24 #include <stdexcept>
25 
26 namespace log4cpp {
27 
34  friend class HierarchyMaintainer;
35 
36  public:
48  static Category& getRoot();
49 
54  static void setRootPriority(Priority::Value priority);
55 
60  static Priority::Value getRootPriority() throw();
61 
69  static Category& getInstance(const std::string& name);
70 
76  static Category* exists(const std::string& name);
77 
90  static std::vector<Category*>* getCurrentCategories();
91 
95  static void shutdown();
96 
101  static void shutdownForced();
102 
106  virtual ~Category();
107 
112  virtual const std::string& getName() const throw();
113 
121  virtual void setPriority(Priority::Value priority)
122  throw(std::invalid_argument);
123 
128  virtual Priority::Value getPriority() const throw();
129 
138  virtual Priority::Value getChainedPriority() const throw();
139 
146  virtual bool isPriorityEnabled(Priority::Value priority) const throw();
147 
155  virtual void addAppender(Appender* appender)
156  throw(std::invalid_argument);
157 
164  virtual void addAppender(Appender& appender);
165 
174  inline void setAppender(Appender* appender) {
175  if (appender) {
176  addAppender(appender);
177  } else {
178  removeAllAppenders();
179  }
180  };
181 
188  inline void setAppender(Appender& appender) {
189  addAppender(appender);
190  };
191 
198  virtual Appender* getAppender() const;
199 
206  virtual Appender* getAppender(const std::string& name) const;
207 
213  virtual AppenderSet getAllAppenders() const;
214 
218  virtual void removeAllAppenders();
219 
224  virtual void removeAppender(Appender* appender);
225 
232  virtual bool ownsAppender() const throw() {
233  return ownsAppender(getAppender());
234  };
235 
241  virtual bool ownsAppender(Appender* appender) const throw();
242 
254  virtual void callAppenders(const LoggingEvent& event) throw();
255 
259  virtual void setAdditivity(bool additivity);
260 
264  virtual bool getAdditivity() const throw();
265 
271  virtual Category* getParent() throw();
272 
278  virtual const Category* getParent() const throw();
279 
287  virtual void log(Priority::Value priority, const char* stringFormat,
288  ...) throw();
289 
295  virtual void log(Priority::Value priority,
296  const std::string& message) throw();
297 
306  virtual void logva(Priority::Value priority,
307  const char* stringFormat,
308  va_list va) throw();
309 
316  void debug(const char* stringFormat, ...) throw();
317 
322  void debug(const std::string& message) throw();
323 
328  inline bool isDebugEnabled() const throw() {
329  return isPriorityEnabled(Priority::DEBUG);
330  };
331 
337  return getStream(Priority::DEBUG);
338  }
339 
346  void info(const char* stringFormat, ...) throw();
347 
352  void info(const std::string& message) throw();
353 
358  inline bool isInfoEnabled() const throw() {
359  return isPriorityEnabled(Priority::INFO);
360  };
361 
367  return getStream(Priority::INFO);
368  }
369 
376  void notice(const char* stringFormat, ...) throw();
377 
382  void notice(const std::string& message) throw();
383 
388  inline bool isNoticeEnabled() const throw() {
389  return isPriorityEnabled(Priority::NOTICE);
390  };
391 
397  return getStream(Priority::NOTICE);
398  }
399 
406  void warn(const char* stringFormat, ...) throw();
407 
412  void warn(const std::string& message) throw();
413 
418  inline bool isWarnEnabled() const throw() {
419  return isPriorityEnabled(Priority::WARN);
420  };
421 
427  return getStream(Priority::WARN);
428  };
429 
436  void error(const char* stringFormat, ...) throw();
437 
442  void error(const std::string& message) throw();
443 
448  inline bool isErrorEnabled() const throw() {
449  return isPriorityEnabled(Priority::ERROR);
450  };
451 
457  return getStream(Priority::ERROR);
458  };
459 
466  void crit(const char* stringFormat, ...) throw();
467 
472  void crit(const std::string& message) throw();
473 
478  inline bool isCritEnabled() const throw() {
479  return isPriorityEnabled(Priority::CRIT);
480  };
481 
487  return getStream(Priority::CRIT);
488  };
489 
496  void alert(const char* stringFormat, ...) throw();
497 
502  void alert(const std::string& message) throw();
503 
508  inline bool isAlertEnabled() const throw() {
509  return isPriorityEnabled(Priority::ALERT);
510  };
511 
516  inline CategoryStream alertStream() throw() {
517  return getStream(Priority::ALERT);
518  };
519 
526  void emerg(const char* stringFormat, ...) throw();
527 
532  void emerg(const std::string& message) throw();
533 
538  inline bool isEmergEnabled() const throw() {
539  return isPriorityEnabled(Priority::EMERG);
540  };
541 
547  return getStream(Priority::EMERG);
548  };
549 
558  void fatal(const char* stringFormat, ...) throw();
559 
566  void fatal(const std::string& message) throw();
567 
574  inline bool isFatalEnabled() const throw() {
575  return isPriorityEnabled(Priority::FATAL);
576  };
577 
585  return getStream(Priority::FATAL);
586  };
587 
593  virtual CategoryStream getStream(Priority::Value priority);
594 
600  virtual CategoryStream operator<<(Priority::Value priority);
601 
602  protected:
603 
612  Category(const std::string& name, Category* parent,
613  Priority::Value priority = Priority::NOTSET);
614 
615  virtual void _logUnconditionally(Priority::Value priority,
616  const char* format,
617  va_list arguments) throw();
618 
624  virtual void _logUnconditionally2(Priority::Value priority,
625  const std::string& message) throw();
626 
627  private:
628 
629  /* prevent copying and assignment */
630  Category(const Category& other);
631  Category& operator=(const Category& other);
632 
634  const std::string _name;
635 
640  Category* _parent;
641 
645  volatile Priority::Value _priority;
646 
647  typedef std::map<Appender *, bool> OwnsAppenderMap;
648 
655  virtual bool ownsAppender(Appender* appender,
656  OwnsAppenderMap::iterator& i2) throw();
657 
658  AppenderSet _appender;
659  mutable threading::Mutex _appenderSetMutex;
660 
666  OwnsAppenderMap _ownsAppender;
667 
672  volatile bool _isAdditive;
673 
674  };
675 
676 }
677 #endif // _LOG4CPP_CATEGORY_HH
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition: Category.hh:426
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition: Category.hh:336
Definition: Priority.hh:77
This is the central class in the log4j package.
Definition: Category.hh:33
ostream & operator<<(ostream &os, const width &w)
Definition: Manipulator.cpp:10
Definition: Priority.hh:70
HierarchyMaintainer is an internal log4cpp class.
Definition: HierarchyMaintainer.hh:27
Definition: Portability.hh:59
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition: Category.hh:366
Definition: Priority.hh:73
Definition: Priority.hh:71
Definition: Priority.hh:72
Definition: Priority.hh:79
This class enables streaming simple types and objects to a category.
Definition: CategoryStream.hh:39
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition: Category.hh:188
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition: Category.hh:584
#define LOG4CPP_EXPORT
Definition: Export.hh:26
The top level namespace for all &#39;Log for C++&#39; types and classes.
Definition: AbortAppender.hh:16
virtual bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition: Category.hh:232
The internal representation of logging events.
Definition: LoggingEvent.hh:32
int Value
The type of Priority Values.
Definition: Priority.hh:85
std::set< Appender * > AppenderSet
Definition: Appender.hh:165
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition: Category.hh:486
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition: Category.hh:456
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition: Category.hh:396
The Priority class provides importance levels with which one can categorize log messages.
Definition: Priority.hh:61
Implement this interface for your own strategies for printing log statements.
Definition: Appender.hh:34
Definition: PThreads.hh:29
class LOG4CPP_EXPORT Category
Definition: CategoryStream.hh:23
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition: Category.hh:516
Definition: Priority.hh:78
Definition: Priority.hh:74
Definition: Priority.hh:75
Definition: Priority.hh:76
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition: Category.hh:546