log4cpp 1.1.3
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 _LOG4CPP_CATEGORY_HH
11#define _LOG4CPP_CATEGORY_HH
12
14#include <log4cpp/Appender.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
26namespace 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
127 virtual Priority::Value getPriority() const throw();
128
137 virtual Priority::Value getChainedPriority() const throw();
138
145 virtual bool isPriorityEnabled(Priority::Value priority) const throw();
146
154 virtual void addAppender(Appender* appender);
155
162 virtual void addAppender(Appender& appender);
163
172 inline void setAppender(Appender* appender) {
173 if (appender) {
174 addAppender(appender);
175 } else {
176 removeAllAppenders();
177 }
178 };
179
186 inline void setAppender(Appender& appender) {
187 addAppender(appender);
188 };
189
196 virtual Appender* getAppender() const;
197
204 virtual Appender* getAppender(const std::string& name) const;
205
211 virtual AppenderSet getAllAppenders() const;
212
216 virtual void removeAllAppenders();
217
222 virtual void removeAppender(Appender* appender);
223
230 virtual bool ownsAppender() const throw() {
231 return ownsAppender(getAppender());
232 };
233
239 virtual bool ownsAppender(Appender* appender) const throw();
240
252 virtual void callAppenders(const LoggingEvent& event) throw();
253
257 virtual void setAdditivity(bool additivity);
258
262 virtual bool getAdditivity() const throw();
263
269 virtual Category* getParent() throw();
270
276 virtual const Category* getParent() const throw();
277
285 virtual void log(Priority::Value priority, const char* stringFormat,
286 ...) throw();
287
293 virtual void log(Priority::Value priority,
294 const std::string& message) throw();
295
304 virtual void logva(Priority::Value priority,
305 const char* stringFormat,
306 va_list va) throw();
307
314 void debug(const char* stringFormat, ...) throw();
315
320 void debug(const std::string& message) throw();
321
326 inline bool isDebugEnabled() const throw() {
327 return isPriorityEnabled(Priority::DEBUG);
328 };
329
335 return getStream(Priority::DEBUG);
336 }
337
344 void info(const char* stringFormat, ...) throw();
345
350 void info(const std::string& message) throw();
351
356 inline bool isInfoEnabled() const throw() {
357 return isPriorityEnabled(Priority::INFO);
358 };
359
365 return getStream(Priority::INFO);
366 }
367
374 void notice(const char* stringFormat, ...) throw();
375
380 void notice(const std::string& message) throw();
381
386 inline bool isNoticeEnabled() const throw() {
387 return isPriorityEnabled(Priority::NOTICE);
388 };
389
395 return getStream(Priority::NOTICE);
396 }
397
404 void warn(const char* stringFormat, ...) throw();
405
410 void warn(const std::string& message) throw();
411
416 inline bool isWarnEnabled() const throw() {
417 return isPriorityEnabled(Priority::WARN);
418 };
419
425 return getStream(Priority::WARN);
426 };
427
434 void error(const char* stringFormat, ...) throw();
435
440 void error(const std::string& message) throw();
441
446 inline bool isErrorEnabled() const throw() {
447 return isPriorityEnabled(Priority::ERROR);
448 };
449
455 return getStream(Priority::ERROR);
456 };
457
464 void crit(const char* stringFormat, ...) throw();
465
470 void crit(const std::string& message) throw();
471
476 inline bool isCritEnabled() const throw() {
477 return isPriorityEnabled(Priority::CRIT);
478 };
479
485 return getStream(Priority::CRIT);
486 };
487
494 void alert(const char* stringFormat, ...) throw();
495
500 void alert(const std::string& message) throw();
501
506 inline bool isAlertEnabled() const throw() {
507 return isPriorityEnabled(Priority::ALERT);
508 };
509
514 inline CategoryStream alertStream() throw() {
515 return getStream(Priority::ALERT);
516 };
517
524 void emerg(const char* stringFormat, ...) throw();
525
530 void emerg(const std::string& message) throw();
531
536 inline bool isEmergEnabled() const throw() {
537 return isPriorityEnabled(Priority::EMERG);
538 };
539
545 return getStream(Priority::EMERG);
546 };
547
556 void fatal(const char* stringFormat, ...) throw();
557
564 void fatal(const std::string& message) throw();
565
572 inline bool isFatalEnabled() const throw() {
573 return isPriorityEnabled(Priority::FATAL);
574 };
575
583 return getStream(Priority::FATAL);
584 };
585
591 virtual CategoryStream getStream(Priority::Value priority);
592
598 virtual CategoryStream operator<<(Priority::Value priority);
599
600 protected:
601
610 Category(const std::string& name, Category* parent,
611 Priority::Value priority = Priority::NOTSET);
612
613 virtual void _logUnconditionally(Priority::Value priority,
614 const char* format,
615 va_list arguments) throw();
616
622 virtual void _logUnconditionally2(Priority::Value priority,
623 const std::string& message) throw();
624
625 private:
626
627 /* prevent copying and assignment */
628 Category(const Category& other);
629 Category& operator=(const Category& other);
630
632 const std::string _name;
633
638 Category* _parent;
639
643 volatile Priority::Value _priority;
644
645 typedef std::map<Appender *, bool> OwnsAppenderMap;
646
653 virtual bool ownsAppender(Appender* appender,
654 OwnsAppenderMap::iterator& i2) throw();
655
656 AppenderSet _appender;
657 mutable threading::Mutex _appenderSetMutex;
658
664 OwnsAppenderMap _ownsAppender;
665
670 volatile bool _isAdditive;
671
672 };
673
674}
675#endif // _LOG4CPP_CATEGORY_HH
#define LOG4CPP_EXPORT
Definition Export.hh:26
Implement this interface for your own strategies for printing log statements.
Definition Appender.hh:34
This class enables streaming simple types and objects to a category.
Definition CategoryStream.hh:39
This is the central class in the log4j package.
Definition Category.hh:33
virtual bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition Category.hh:230
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition Category.hh:484
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition Category.hh:514
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition Category.hh:394
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition Category.hh:544
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition Category.hh:364
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition Category.hh:582
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition Category.hh:424
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition Category.hh:186
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition Category.hh:454
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition Category.hh:334
HierarchyMaintainer is an internal log4cpp class.
Definition HierarchyMaintainer.hh:27
The Priority class provides importance levels with which one can categorize log messages.
Definition Priority.hh:61
int Value
The type of Priority Values.
Definition Priority.hh:85
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:165
ostream & operator<<(ostream &os, const width &w)
Definition Manipulator.cpp:10
Definition Portability.hh:59
The internal representation of logging events.
Definition LoggingEvent.hh:32