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
14#include <log4shib/Appender.hh>
16#include <log4shib/Priority.hh>
19
20#include <map>
21#include <vector>
22#include <cstdarg>
23#include <stdexcept>
24
25namespace 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 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
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
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
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
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
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
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
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
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,
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
#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:181
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition: Category.hh:419
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition: Category.hh:479
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition: Category.hh:539
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition: Category.hh:329
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition: Category.hh:389
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition: Category.hh:509
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition: Category.hh:449
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition: Category.hh:359
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition: Category.hh:577
bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition: Category.hh:225
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