log4shib 2.0.0

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>
17#include <log4shib/CategoryStream.hh>
18#include <log4shib/threading/Threading.hh>
19
20#include <map>
21#include <vector>
22#include <cstdarg>
23#include <stdexcept>
24
25 namespace log4shib {
26
32 class LOG4SHIB_EXPORT Category {
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 throw(std::invalid_argument);
116
121 virtual Priority::Value getPriority() const throw();
122
131 virtual Priority::Value getChainedPriority() const throw();
132
139 virtual bool isPriorityEnabled(Priority::Value priority) const throw();
140
148 virtual void addAppender(Appender* appender)
149 throw(std::invalid_argument);
150
157 virtual void addAppender(Appender& appender);
158
167 inline void setAppender(Appender* appender) {
168 if (appender) {
169 addAppender(appender);
170 } else {
171 removeAllAppenders();
172 }
173 };
174
181 inline void setAppender(Appender& appender) {
182 addAppender(appender);
183 };
184
191 virtual Appender* getAppender() const;
192
199 virtual Appender* getAppender(const std::string& name) const;
200
206 virtual AppenderSet getAllAppenders() const;
207
211 virtual void removeAllAppenders();
212
217 virtual void removeAppender(Appender* appender);
218
225 inline bool ownsAppender() const throw() {
226 return ownsAppender(getAppender());
227 };
228
234 virtual bool ownsAppender(Appender* appender) const throw();
235
247 virtual void callAppenders(const LoggingEvent& event) throw();
248
252 virtual void setAdditivity(bool additivity);
253
257 virtual bool getAdditivity() const throw();
258
264 virtual Category* getParent() throw();
265
271 virtual const Category* getParent() const throw();
272
280 virtual void log(Priority::Value priority, const char* stringFormat,
281 ...) throw();
282
288 virtual void log(Priority::Value priority,
289 const std::string& message) throw();
290
299 virtual void logva(Priority::Value priority,
300 const char* stringFormat,
301 va_list va) throw();
302
309 void debug(const char* stringFormat, ...) throw();
310
315 void debug(const std::string& message) throw();
316
321 inline bool isDebugEnabled() const throw() {
322 return isPriorityEnabled(Priority::DEBUG);
323 };
324
329 inline CategoryStream debugStream() {
330 return getStream(Priority::DEBUG);
331 }
332
339 void info(const char* stringFormat, ...) throw();
340
345 void info(const std::string& message) throw();
346
351 inline bool isInfoEnabled() const throw() {
352 return isPriorityEnabled(Priority::INFO);
353 };
354
359 inline CategoryStream infoStream() {
360 return getStream(Priority::INFO);
361 }
362
369 void notice(const char* stringFormat, ...) throw();
370
375 void notice(const std::string& message) throw();
376
381 inline bool isNoticeEnabled() const throw() {
382 return isPriorityEnabled(Priority::NOTICE);
383 };
384
389 inline CategoryStream noticeStream() {
390 return getStream(Priority::NOTICE);
391 }
392
399 void warn(const char* stringFormat, ...) throw();
400
405 void warn(const std::string& message) throw();
406
411 inline bool isWarnEnabled() const throw() {
412 return isPriorityEnabled(Priority::WARN);
413 };
414
419 inline CategoryStream warnStream() {
420 return getStream(Priority::WARN);
421 };
422
429 void error(const char* stringFormat, ...) throw();
430
435 void error(const std::string& message) throw();
436
441 inline bool isErrorEnabled() const throw() {
442 return isPriorityEnabled(Priority::ERROR);
443 };
444
449 inline CategoryStream errorStream() {
450 return getStream(Priority::ERROR);
451 };
452
459 void crit(const char* stringFormat, ...) throw();
460
465 void crit(const std::string& message) throw();
466
471 inline bool isCritEnabled() const throw() {
472 return isPriorityEnabled(Priority::CRIT);
473 };
474
479 inline CategoryStream critStream() {
480 return getStream(Priority::CRIT);
481 };
482
489 void alert(const char* stringFormat, ...) throw();
490
495 void alert(const std::string& message) throw();
496
501 inline bool isAlertEnabled() const throw() {
502 return isPriorityEnabled(Priority::ALERT);
503 };
504
509 inline CategoryStream alertStream() throw() {
510 return getStream(Priority::ALERT);
511 };
512
519 void emerg(const char* stringFormat, ...) throw();
520
525 void emerg(const std::string& message) throw();
526
531 inline bool isEmergEnabled() const throw() {
532 return isPriorityEnabled(Priority::EMERG);
533 };
534
539 inline CategoryStream emergStream() {
540 return getStream(Priority::EMERG);
541 };
542
551 void fatal(const char* stringFormat, ...) throw();
552
559 void fatal(const std::string& message) throw();
560
567 inline bool isFatalEnabled() const throw() {
568 return isPriorityEnabled(Priority::FATAL);
569 };
570
577 inline CategoryStream fatalStream() {
578 return getStream(Priority::FATAL);
579 };
580
586 virtual CategoryStream getStream(Priority::Value priority);
587
593 virtual CategoryStream operator<<(Priority::Value priority);
594
595 protected:
596
605 Category(const std::string& name, Category* parent,
606 Priority::Value priority = Priority::NOTSET);
607
608 virtual void _logUnconditionally(Priority::Value priority,
609 const char* format,
610 va_list arguments) throw();
611
617 virtual void _logUnconditionally2(Priority::Value priority,
618 const std::string& message) throw();
619
620 private:
621
622 /* prevent copying and assignment */
623 Category(const Category& other);
624 Category& operator=(const Category& other);
625
627 const std::string _name;
628
633 Category* _parent;
634
638 volatile Priority::Value _priority;
639
640 typedef std::map<Appender *, bool> OwnsAppenderMap;
641
648 virtual bool ownsAppender(Appender* appender,
649 OwnsAppenderMap::iterator& i2) throw();
650
651 AppenderSet _appender;
652 mutable threading::Mutex _appenderSetMutex;
653
659 OwnsAppenderMap _ownsAppender;
660
665 volatile bool _isAdditive;
666
667 };
668
669}
670#endif // _LOG4SHIB_CATEGORY_HH
Appender.hh
CategoryStream.hh
LOG4SHIB_EXPORT
#define LOG4SHIB_EXPORT
Definition: Export.hh:11
LoggingEvent.hh
Portability.hh
Priority.hh
Threading.hh
log4shib::Appender
Implement this interface for your own strategies for printing log statements.
Definition: Appender.hh:33
log4shib::CategoryStream
This class enables streaming simple types and objects to a category.
Definition: CategoryStream.hh:33
log4shib::Category
This is the central class in the log4j package.
Definition: Category.hh:32
log4shib::Category::setAppender
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition: Category.hh:181
log4shib::Category::warnStream
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition: Category.hh:419
log4shib::Category::critStream
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition: Category.hh:479
log4shib::Category::emergStream
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition: Category.hh:539
log4shib::Category::debugStream
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition: Category.hh:329
log4shib::Category::noticeStream
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition: Category.hh:389
log4shib::Category::alertStream
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition: Category.hh:509
log4shib::Category::errorStream
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition: Category.hh:449
log4shib::Category::infoStream
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition: Category.hh:359
log4shib::Category::fatalStream
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition: Category.hh:577
log4shib::Category::ownsAppender
bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition: Category.hh:225
log4shib::HierarchyMaintainer
HierarchyMaintainer is an internal log4shib class.
Definition: HierarchyMaintainer.hh:27
log4shib::Priority
The Priority class provides importance levels with which one can categorize log messages.
Definition: Priority.hh:62
log4shib::Priority::EMERG
@ EMERG
Definition: Priority.hh:69
log4shib::Priority::WARN
@ WARN
Definition: Priority.hh:74
log4shib::Priority::NOTSET
@ NOTSET
Definition: Priority.hh:78
log4shib::Priority::ERROR
@ ERROR
Definition: Priority.hh:73
log4shib::Priority::FATAL
@ FATAL
Definition: Priority.hh:70
log4shib::Priority::ALERT
@ ALERT
Definition: Priority.hh:71
log4shib::Priority::DEBUG
@ DEBUG
Definition: Priority.hh:77
log4shib::Priority::CRIT
@ CRIT
Definition: Priority.hh:72
log4shib::Priority::NOTICE
@ NOTICE
Definition: Priority.hh:75
log4shib::Priority::INFO
@ INFO
Definition: Priority.hh:76
log4shib::Priority::Value
int Value
The type of Priority Values.
Definition: Priority.hh:84
log4shib::threading::Mutex
Definition: PThreads.hh:29
log4shib
The top level namespace for all 'Log for C++' types and classes.
Definition: AbortAppender.hh:16
log4shib::AppenderSet
std::set< Appender * > AppenderSet
Definition: Appender.hh:147
log4shib::Category
class LOG4SHIB_EXPORT Category
Definition: CategoryStream.hh:21
std
Definition: Portability.hh:37
log4shib::LoggingEvent
The internal representation of logging events.
Definition: LoggingEvent.hh:32