log4shib 2.0.1
Loading...
Searching...
No Matches
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
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 {
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() {
321 };
322
330
337 void info(const char* stringFormat, ...) throw();
338
343 void info(const std::string& message) throw();
344
349 inline bool isInfoEnabled() const throw() {
351 };
352
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() {
381 };
382
390
397 void warn(const char* stringFormat, ...) throw();
398
403 void warn(const std::string& message) throw();
404
409 inline bool isWarnEnabled() const throw() {
411 };
412
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() {
441 };
442
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() {
471 };
472
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() {
501 };
502
507 inline CategoryStream alertStream() throw() {
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() {
531 };
532
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() {
567 };
568
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,
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
645
646 virtual bool ownsAppender(Appender* appender,
647 OwnsAppenderMap::iterator& i2) throw();
648
649 AppenderSet _appender;
650 mutable threading::Mutex _appenderSetMutex;
651
656
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
bool isNoticeEnabled() const
Return true if the Category will log messages with priority NOTICE.
Definition Category.hh:379
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition Category.hh:179
friend class HierarchyMaintainer
Definition Category.hh:33
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition Category.hh:417
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition Category.hh:477
static void setRootPriority(Priority::Value priority)
Set the priority of the root Category.
Definition Category.cpp:27
Category(const std::string &name, Category *parent, Priority::Value priority=Priority::NOTSET)
Constructor.
Definition Category.cpp:52
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition Category.hh:537
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition Category.hh:327
virtual Priority::Value getChainedPriority() const
Starting from this Category, search the category hierarchy for a set priority and return it.
Definition Category.cpp:82
bool isFatalEnabled() const
Return true if the Category will log messages with priority FATAL.
Definition Category.hh:565
virtual CategoryStream getStream(Priority::Value priority)
Return a CategoryStream with given Priority.
Definition Category.cpp:415
static Category & getRoot()
Return the root of the Category hierarchy.
Definition Category.cpp:23
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition Category.hh:387
virtual void removeAllAppenders()
Removes all appenders for this Category.
Definition Category.cpp:149
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition Category.hh:507
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition Category.hh:447
static Category & getInstance(const std::string &name)
Instantiate a Category with name name.
Definition Category.cpp:35
bool isDebugEnabled() const
Return true if the Category will log messages with priority DEBUG.
Definition Category.hh:319
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition Category.hh:357
virtual Priority::Value getPriority() const
Returns the assigned Priority, if any, for this Category.
Definition Category.cpp:67
virtual bool isPriorityEnabled(Priority::Value priority) const
Returns true if the chained priority of the Category is equal to or higher than given priority.
Definition Category.cpp:261
static std::vector< Category * > * getCurrentCategories()
Returns all the currently defined categories as a vector of Category pointers.
Definition Category.cpp:43
bool isEmergEnabled() const
Return true if the Category will log messages with priority EMERG.
Definition Category.hh:529
virtual void addAppender(Appender *appender)
Adds an Appender to this Category.
Definition Category.cpp:93
bool isWarnEnabled() const
Return true if the Category will log messages with priority WARN.
Definition Category.hh:409
static Priority::Value getRootPriority()
Get the priority of the root Category.
Definition Category.cpp:31
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition Category.hh:575
static void shutdown()
This method will remove all Appenders from Categories.XXX.
Definition Category.cpp:48
bool isErrorEnabled() const
Return true if the Category will log messages with priority ERROR.
Definition Category.hh:439
virtual void setPriority(Priority::Value priority)
Set the priority of this Category.
Definition Category.cpp:71
static Category * exists(const std::string &name)
If the named category exists (in the default hierarchy) then it returns a reference to the category,...
Definition Category.cpp:39
bool isAlertEnabled() const
Return true if the Category will log messages with priority ALERT.
Definition Category.hh:499
void setAppender(Appender *appender)
Adds an Appender to this Category.
Definition Category.hh:165
virtual const std::string & getName() const
Return the category name.
Definition Category.cpp:63
bool isInfoEnabled() const
Return true if the Category will log messages with priority INFO.
Definition Category.hh:349
virtual Appender * getAppender() const
Returns the first Appender for this Category, or NULL if no Appender has been set.
Definition Category.cpp:120
bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition Category.hh:223
bool isCritEnabled() const
Return true if the Category will log messages with priority CRIT.
Definition Category.hh:469
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
Definition Portability.hh:37
The internal representation of logging events.
Definition LoggingEvent.hh:32