log4shib  2.0.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 _LOG4SHIB_CATEGORY_HH
11 #define _LOG4SHIB_CATEGORY_HH
12 
13 #include <log4shib/Portability.hh>
14 #include <log4shib/Appender.hh>
15 #include <log4shib/LoggingEvent.hh>
16 #include <log4shib/Priority.hh>
19 
20 #include <map>
21 #include <vector>
22 #include <cstdarg>
23 #include <stdexcept>
24 
25 namespace log4shib {
26 
33  friend class HierarchyMaintainer;
34 
35  public:
47  static Category& getRoot();
48 
53  static void setRootPriority(Priority::Value priority);
54 
59  static Priority::Value getRootPriority() throw();
60 
68  static Category& getInstance(const std::string& name);
69 
75  static Category* exists(const std::string& name);
76 
89  static std::vector<Category*>* getCurrentCategories();
90 
94  static void shutdown();
95 
99  virtual ~Category();
100 
105  virtual const std::string& getName() const throw();
106 
114  virtual void setPriority(Priority::Value priority);
115 
120  virtual Priority::Value getPriority() const throw();
121 
130  virtual Priority::Value getChainedPriority() const throw();
131 
138  virtual bool isPriorityEnabled(Priority::Value priority) const throw();
139 
147  virtual void addAppender(Appender* appender);
148 
155  virtual void addAppender(Appender& appender);
156 
165  inline void setAppender(Appender* appender) {
166  if (appender) {
167  addAppender(appender);
168  } else {
169  removeAllAppenders();
170  }
171  };
172 
179  inline void setAppender(Appender& appender) {
180  addAppender(appender);
181  };
182 
189  virtual Appender* getAppender() const;
190 
197  virtual Appender* getAppender(const std::string& name) const;
198 
204  virtual AppenderSet getAllAppenders() const;
205 
209  virtual void removeAllAppenders();
210 
215  virtual void removeAppender(Appender* appender);
216 
223  inline bool ownsAppender() const throw() {
224  return ownsAppender(getAppender());
225  };
226 
232  virtual bool ownsAppender(Appender* appender) const throw();
233 
245  virtual void callAppenders(const LoggingEvent& event) throw();
246 
250  virtual void setAdditivity(bool additivity);
251 
255  virtual bool getAdditivity() const throw();
256 
262  virtual Category* getParent() throw();
263 
269  virtual const Category* getParent() const throw();
270 
278  virtual void log(Priority::Value priority, const char* stringFormat,
279  ...) throw();
280 
286  virtual void log(Priority::Value priority,
287  const std::string& message) throw();
288 
297  virtual void logva(Priority::Value priority,
298  const char* stringFormat,
299  va_list va) throw();
300 
307  void debug(const char* stringFormat, ...) throw();
308 
313  void debug(const std::string& message) throw();
314 
319  inline bool isDebugEnabled() const throw() {
320  return isPriorityEnabled(Priority::DEBUG);
321  };
322 
328  return getStream(Priority::DEBUG);
329  }
330 
337  void info(const char* stringFormat, ...) throw();
338 
343  void info(const std::string& message) throw();
344 
349  inline bool isInfoEnabled() const throw() {
350  return isPriorityEnabled(Priority::INFO);
351  };
352 
358  return getStream(Priority::INFO);
359  }
360 
367  void notice(const char* stringFormat, ...) throw();
368 
373  void notice(const std::string& message) throw();
374 
379  inline bool isNoticeEnabled() const throw() {
380  return isPriorityEnabled(Priority::NOTICE);
381  };
382 
388  return getStream(Priority::NOTICE);
389  }
390 
397  void warn(const char* stringFormat, ...) throw();
398 
403  void warn(const std::string& message) throw();
404 
409  inline bool isWarnEnabled() const throw() {
410  return isPriorityEnabled(Priority::WARN);
411  };
412 
418  return getStream(Priority::WARN);
419  };
420 
427  void error(const char* stringFormat, ...) throw();
428 
433  void error(const std::string& message) throw();
434 
439  inline bool isErrorEnabled() const throw() {
440  return isPriorityEnabled(Priority::ERROR);
441  };
442 
448  return getStream(Priority::ERROR);
449  };
450 
457  void crit(const char* stringFormat, ...) throw();
458 
463  void crit(const std::string& message) throw();
464 
469  inline bool isCritEnabled() const throw() {
470  return isPriorityEnabled(Priority::CRIT);
471  };
472 
478  return getStream(Priority::CRIT);
479  };
480 
487  void alert(const char* stringFormat, ...) throw();
488 
493  void alert(const std::string& message) throw();
494 
499  inline bool isAlertEnabled() const throw() {
500  return isPriorityEnabled(Priority::ALERT);
501  };
502 
507  inline CategoryStream alertStream() throw() {
508  return getStream(Priority::ALERT);
509  };
510 
517  void emerg(const char* stringFormat, ...) throw();
518 
523  void emerg(const std::string& message) throw();
524 
529  inline bool isEmergEnabled() const throw() {
530  return isPriorityEnabled(Priority::EMERG);
531  };
532 
538  return getStream(Priority::EMERG);
539  };
540 
549  void fatal(const char* stringFormat, ...) throw();
550 
557  void fatal(const std::string& message) throw();
558 
565  inline bool isFatalEnabled() const throw() {
566  return isPriorityEnabled(Priority::FATAL);
567  };
568 
576  return getStream(Priority::FATAL);
577  };
578 
584  virtual CategoryStream getStream(Priority::Value priority);
585 
591  virtual CategoryStream operator<<(Priority::Value priority);
592 
593  protected:
594 
603  Category(const std::string& name, Category* parent,
604  Priority::Value priority = Priority::NOTSET);
605 
606  virtual void _logUnconditionally(Priority::Value priority,
607  const char* format,
608  va_list arguments) throw();
609 
615  virtual void _logUnconditionally2(Priority::Value priority,
616  const std::string& message) throw();
617 
618  private:
619 
620  /* prevent copying and assignment */
621  Category(const Category& other);
622  Category& operator=(const Category& other);
623 
625  const std::string _name;
626 
631  Category* _parent;
632 
636  volatile Priority::Value _priority;
637 
638  typedef std::map<Appender *, bool> OwnsAppenderMap;
639 
646  virtual bool ownsAppender(Appender* appender,
647  OwnsAppenderMap::iterator& i2) throw();
648 
649  AppenderSet _appender;
650  mutable threading::Mutex _appenderSetMutex;
651 
657  OwnsAppenderMap _ownsAppender;
658 
663  volatile bool _isAdditive;
664 
665  };
666 
667 }
668 #endif // _LOG4SHIB_CATEGORY_HH
#define LOG4SHIB_EXPORT
Definition: Export.hh:11
Implement this interface for your own strategies for printing log statements.
Definition: Appender.hh:33
This class enables streaming simple types and objects to a category.
Definition: CategoryStream.hh:33
This is the central class in the log4j package.
Definition: Category.hh:32
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition: Category.hh:179
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition: Category.hh:417
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition: Category.hh:477
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition: Category.hh:537
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition: Category.hh:327
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition: Category.hh:387
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition: Category.hh:507
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition: Category.hh:447
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition: Category.hh:357
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition: Category.hh:575
bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition: Category.hh:223
HierarchyMaintainer is an internal log4shib class.
Definition: HierarchyMaintainer.hh:27
The Priority class provides importance levels with which one can categorize log messages.
Definition: Priority.hh:62
@ EMERG
Definition: Priority.hh:69
@ WARN
Definition: Priority.hh:74
@ NOTSET
Definition: Priority.hh:78
@ ERROR
Definition: Priority.hh:73
@ FATAL
Definition: Priority.hh:70
@ ALERT
Definition: Priority.hh:71
@ DEBUG
Definition: Priority.hh:77
@ CRIT
Definition: Priority.hh:72
@ NOTICE
Definition: Priority.hh:75
@ INFO
Definition: Priority.hh:76
int Value
The type of Priority Values.
Definition: Priority.hh:84
Definition: PThreads.hh:29
The top level namespace for all 'Log for C++' types and classes.
Definition: AbortAppender.hh:16
std::set< Appender * > AppenderSet
Definition: Appender.hh:147
class LOG4SHIB_EXPORT Category
Definition: CategoryStream.hh:21
Definition: Portability.hh:37
The internal representation of logging events.
Definition: LoggingEvent.hh:32