log4cpp 1.1.6
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
13#include <log4cpp/Appender.hh>
17#include <log4cpp/Priority.hh>
19
20#include <cstdarg>
21#include <map>
22#include <stdexcept>
23#include <vector>
24
25namespace log4cpp {
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() LOG4CPP_NOTHROW;
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
100 static void shutdownForced();
101
105 virtual ~Category();
106
111 virtual const std::string& getName() const LOG4CPP_NOTHROW;
112
120 virtual void setPriority(Priority::Value priority);
121
126 virtual Priority::Value getPriority() const LOG4CPP_NOTHROW;
127
136 virtual Priority::Value getChainedPriority() const LOG4CPP_NOTHROW;
137
144 virtual bool isPriorityEnabled(Priority::Value priority) const LOG4CPP_NOTHROW;
145
153 virtual void addAppender(Appender* appender);
154
161 virtual void addAppender(Appender& appender);
162
171 inline void setAppender(Appender* appender) {
172 if (appender) {
173 addAppender(appender);
174 } else {
175 removeAllAppenders();
176 }
177 };
178
186 addAppender(appender);
187 };
188
195 virtual Appender* getAppender() const;
196
203 virtual Appender* getAppender(const std::string& name) const;
204
210 virtual AppenderSet getAllAppenders() const;
211
215 virtual void removeAllAppenders();
216
221 virtual void removeAppender(Appender* appender);
222
230 return ownsAppender(getAppender());
231 };
232
238 virtual bool ownsAppender(Appender* appender) const LOG4CPP_NOTHROW;
239
251 virtual void callAppenders(const LoggingEvent& event) LOG4CPP_NOTHROW;
252
256 virtual void setAdditivity(bool additivity);
257
261 virtual bool getAdditivity() const LOG4CPP_NOTHROW;
262
268 virtual Category* getParent() LOG4CPP_NOTHROW;
269
276
284 virtual void log(Priority::Value priority, const char* stringFormat, ...) LOG4CPP_NOTHROW;
285
291 virtual void log(Priority::Value priority, const std::string& message) LOG4CPP_NOTHROW;
292
301 virtual void logva(Priority::Value priority, const char* stringFormat, va_list va) LOG4CPP_NOTHROW;
302
309 void debug(const char* stringFormat, ...) LOG4CPP_NOTHROW;
310
315 void debug(const std::string& message) LOG4CPP_NOTHROW;
316
321 inline bool isDebugEnabled() const LOG4CPP_NOTHROW {
322 return isPriorityEnabled(Priority::DEBUG);
323 };
324
330 return getStream(Priority::DEBUG);
331 }
332
339 void info(const char* stringFormat, ...) LOG4CPP_NOTHROW;
340
345 void info(const std::string& message) LOG4CPP_NOTHROW;
346
351 inline bool isInfoEnabled() const LOG4CPP_NOTHROW {
352 return isPriorityEnabled(Priority::INFO);
353 };
354
360 return getStream(Priority::INFO);
361 }
362
369 void notice(const char* stringFormat, ...) LOG4CPP_NOTHROW;
370
375 void notice(const std::string& message) LOG4CPP_NOTHROW;
376
381 inline bool isNoticeEnabled() const LOG4CPP_NOTHROW {
382 return isPriorityEnabled(Priority::NOTICE);
383 };
384
390 return getStream(Priority::NOTICE);
391 }
392
399 void warn(const char* stringFormat, ...) LOG4CPP_NOTHROW;
400
405 void warn(const std::string& message) LOG4CPP_NOTHROW;
406
411 inline bool isWarnEnabled() const LOG4CPP_NOTHROW {
412 return isPriorityEnabled(Priority::WARN);
413 };
414
420 return getStream(Priority::WARN);
421 };
422
429 void error(const char* stringFormat, ...) LOG4CPP_NOTHROW;
430
435 void error(const std::string& message) LOG4CPP_NOTHROW;
436
441 inline bool isErrorEnabled() const LOG4CPP_NOTHROW {
442 return isPriorityEnabled(Priority::ERROR);
443 };
444
450 return getStream(Priority::ERROR);
451 };
452
459 void crit(const char* stringFormat, ...) LOG4CPP_NOTHROW;
460
465 void crit(const std::string& message) LOG4CPP_NOTHROW;
466
471 inline bool isCritEnabled() const LOG4CPP_NOTHROW {
472 return isPriorityEnabled(Priority::CRIT);
473 };
474
480 return getStream(Priority::CRIT);
481 };
482
489 void alert(const char* stringFormat, ...) LOG4CPP_NOTHROW;
490
495 void alert(const std::string& message) LOG4CPP_NOTHROW;
496
501 inline bool isAlertEnabled() const LOG4CPP_NOTHROW {
502 return isPriorityEnabled(Priority::ALERT);
503 };
504
510 return getStream(Priority::ALERT);
511 };
512
519 void emerg(const char* stringFormat, ...) LOG4CPP_NOTHROW;
520
525 void emerg(const std::string& message) LOG4CPP_NOTHROW;
526
531 inline bool isEmergEnabled() const LOG4CPP_NOTHROW {
532 return isPriorityEnabled(Priority::EMERG);
533 };
534
540 return getStream(Priority::EMERG);
541 };
542
551 void fatal(const char* stringFormat, ...) LOG4CPP_NOTHROW;
552
559 void fatal(const std::string& message) LOG4CPP_NOTHROW;
560
567 inline bool isFatalEnabled() const LOG4CPP_NOTHROW {
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:
604 Category(const std::string& name, Category* parent, Priority::Value priority = Priority::NOTSET);
605
606 virtual void _logUnconditionally(Priority::Value priority, const char* format,
608
614 virtual void _logUnconditionally2(Priority::Value priority, const std::string& message) LOG4CPP_NOTHROW;
615
616 private:
617 /* prevent copying and assignment */
618 Category(const Category& other);
619 Category& operator=(const Category& other);
620
622 const std::string _name;
623
628 Category* _parent;
629
633 volatile Priority::Value _priority;
634
635 typedef std::map<Appender*, bool> OwnsAppenderMap;
636
643 virtual bool ownsAppender(Appender* appender, OwnsAppenderMap::iterator& i2) LOG4CPP_NOTHROW;
644
645 AppenderSet _appender;
646 mutable threading::Mutex _appenderSetMutex;
647
653 OwnsAppenderMap _ownsAppender;
654
659 volatile bool _isAdditive;
660 };
661
662} // namespace log4cpp
663#endif // _LOG4CPP_CATEGORY_HH
#define LOG4CPP_EXPORT
Definition Export.hh:26
#define LOG4CPP_UNIQUE_PTR
Definition Portability.hh:75
#define LOG4CPP_NOTHROW
Definition Portability.hh:82
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:32
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition Category.hh:479
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition Category.hh:389
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition Category.hh:539
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition Category.hh:359
CategoryStream alertStream() LOG4CPP_NOTHROW
Return a CategoryStream with priority ALERT.
Definition Category.hh:509
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition Category.hh:577
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition Category.hh:419
virtual bool ownsAppender() const LOG4CPP_NOTHROW
Returns true if the Category owns the first Appender in its Appender set.
Definition Category.hh:229
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition Category.hh:185
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition Category.hh:449
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition Category.hh:329
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:28
The top level namespace for all 'Log for C++' types and classes.
Definition AbortAppender.hh:16
ostream & operator<<(ostream &os, const width &w)
Definition Manipulator.cpp:10
std::set< Appender * > AppenderSet
Definition Appender.hh:177
Definition Portability.hh:61
The internal representation of logging events.
Definition LoggingEvent.hh:32