Loading...
Searching...
No Matches
Category.hh
Go to the documentation of this file.
/*
* Category.hh
*
* Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
* Copyright 2000, Bastiaan Bakker. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#ifndef _LOG4SHIB_CATEGORY_HH
#define _LOG4SHIB_CATEGORY_HH
#include <log4shib/Portability.hh>
#include <log4shib/Appender.hh>
#include <log4shib/LoggingEvent.hh>
#include <log4shib/Priority.hh>
#include <log4shib/CategoryStream.hh>
#include <log4shib/threading/Threading.hh>
#include <map>
#include <vector>
#include <cstdarg>
#include <stdexcept>
namespace log4shib {
class LOG4SHIB_EXPORT Category {
friend class HierarchyMaintainer;
public:
static Category& getRoot();
static void setRootPriority(Priority::Value priority);
static Priority::Value getRootPriority() throw();
static Category& getInstance(const std::string& name);
static Category* exists(const std::string& name);
static std::vector<Category*>* getCurrentCategories();
static void shutdown();
virtual ~Category();
virtual const std::string& getName() const throw();
virtual void setPriority(Priority::Value priority);
virtual Priority::Value getPriority() const throw();
virtual Priority::Value getChainedPriority() const throw();
virtual bool isPriorityEnabled(Priority::Value priority) const throw();
virtual void addAppender(Appender* appender);
virtual void addAppender(Appender& appender);
inline void setAppender(Appender* appender) {
if (appender) {
addAppender(appender);
} else {
removeAllAppenders();
}
};
inline void setAppender(Appender& appender) {
addAppender(appender);
};
virtual Appender* getAppender() const;
virtual Appender* getAppender(const std::string& name) const;
virtual AppenderSet getAllAppenders() const;
virtual void removeAllAppenders();
virtual void removeAppender(Appender* appender);
inline bool ownsAppender() const throw() {
return ownsAppender(getAppender());
};
virtual bool ownsAppender(Appender* appender) const throw();
virtual void callAppenders(const LoggingEvent& event) throw();
virtual void setAdditivity(bool additivity);
virtual bool getAdditivity() const throw();
virtual Category* getParent() throw();
virtual const Category* getParent() const throw();
virtual void log(Priority::Value priority, const char* stringFormat,
...) throw();
virtual void log(Priority::Value priority,
const std::string& message) throw();
virtual void logva(Priority::Value priority,
const char* stringFormat,
va_list va) throw();
void debug(const char* stringFormat, ...) throw();
void debug(const std::string& message) throw();
inline bool isDebugEnabled() const throw() {
return isPriorityEnabled(Priority::DEBUG);
};
inline CategoryStream debugStream() {
return getStream(Priority::DEBUG);
}
void info(const char* stringFormat, ...) throw();
void info(const std::string& message) throw();
inline bool isInfoEnabled() const throw() {
return isPriorityEnabled(Priority::INFO);
};
inline CategoryStream infoStream() {
return getStream(Priority::INFO);
}
void notice(const char* stringFormat, ...) throw();
void notice(const std::string& message) throw();
inline bool isNoticeEnabled() const throw() {
return isPriorityEnabled(Priority::NOTICE);
};
inline CategoryStream noticeStream() {
return getStream(Priority::NOTICE);
}
void warn(const char* stringFormat, ...) throw();
void warn(const std::string& message) throw();
inline bool isWarnEnabled() const throw() {
return isPriorityEnabled(Priority::WARN);
};
inline CategoryStream warnStream() {
return getStream(Priority::WARN);
};
void error(const char* stringFormat, ...) throw();
void error(const std::string& message) throw();
inline bool isErrorEnabled() const throw() {
return isPriorityEnabled(Priority::ERROR);
};
inline CategoryStream errorStream() {
return getStream(Priority::ERROR);
};
void crit(const char* stringFormat, ...) throw();
void crit(const std::string& message) throw();
inline bool isCritEnabled() const throw() {
return isPriorityEnabled(Priority::CRIT);
};
inline CategoryStream critStream() {
return getStream(Priority::CRIT);
};
void alert(const char* stringFormat, ...) throw();
void alert(const std::string& message) throw();
inline bool isAlertEnabled() const throw() {
return isPriorityEnabled(Priority::ALERT);
};
inline CategoryStream alertStream() throw() {
return getStream(Priority::ALERT);
};
void emerg(const char* stringFormat, ...) throw();
void emerg(const std::string& message) throw();
inline bool isEmergEnabled() const throw() {
return isPriorityEnabled(Priority::EMERG);
};
inline CategoryStream emergStream() {
return getStream(Priority::EMERG);
};
void fatal(const char* stringFormat, ...) throw();
void fatal(const std::string& message) throw();
inline bool isFatalEnabled() const throw() {
return isPriorityEnabled(Priority::FATAL);
};
inline CategoryStream fatalStream() {
return getStream(Priority::FATAL);
};
virtual CategoryStream getStream(Priority::Value priority);
virtual CategoryStream operator<<(Priority::Value priority);
protected:
Category(const std::string& name, Category* parent,
Priority::Value priority = Priority::NOTSET);
virtual void _logUnconditionally(Priority::Value priority,
const char* format,
va_list arguments) throw();
virtual void _logUnconditionally2(Priority::Value priority,
const std::string& message) throw();
private:
/* prevent copying and assignment */
Category(const Category& other);
Category& operator=(const Category& other);
const std::string _name;
Category* _parent;
volatile Priority::Value _priority;
typedef std::map<Appender *, bool> OwnsAppenderMap;
virtual bool ownsAppender(Appender* appender,
OwnsAppenderMap::iterator& i2) throw();
AppenderSet _appender;
mutable threading::Mutex _appenderSetMutex;
OwnsAppenderMap _ownsAppender;
volatile bool _isAdditive;
};
}
#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::isNoticeEnabled
bool isNoticeEnabled() const
Return true if the Category will log messages with priority NOTICE.
Definition Category.hh:379
log4shib::Category::setAppender
void setAppender(Appender &appender)
Adds an Appender for this Category.
Definition Category.hh:179
log4shib::Category::HierarchyMaintainer
friend class HierarchyMaintainer
Definition Category.hh:33
log4shib::Category::warnStream
CategoryStream warnStream()
Return a CategoryStream with priority WARN.
Definition Category.hh:417
log4shib::Category::critStream
CategoryStream critStream()
Return a CategoryStream with priority CRIT.
Definition Category.hh:477
log4shib::Category::setRootPriority
static void setRootPriority(Priority::Value priority)
Set the priority of the root Category.
Definition Category.cpp:27
log4shib::Category::Category
Category(const std::string &name, Category *parent, Priority::Value priority=Priority::NOTSET)
Constructor.
Definition Category.cpp:52
log4shib::Category::emergStream
CategoryStream emergStream()
Return a CategoryStream with priority EMERG.
Definition Category.hh:537
log4shib::Category::debugStream
CategoryStream debugStream()
Return a CategoryStream with priority DEBUG.
Definition Category.hh:327
log4shib::Category::getChainedPriority
virtual Priority::Value getChainedPriority() const
Starting from this Category, search the category hierarchy for a set priority and return it.
Definition Category.cpp:82
log4shib::Category::isFatalEnabled
bool isFatalEnabled() const
Return true if the Category will log messages with priority FATAL.
Definition Category.hh:565
log4shib::Category::getStream
virtual CategoryStream getStream(Priority::Value priority)
Return a CategoryStream with given Priority.
Definition Category.cpp:415
log4shib::Category::getRoot
static Category & getRoot()
Return the root of the Category hierarchy.
Definition Category.cpp:23
log4shib::Category::noticeStream
CategoryStream noticeStream()
Return a CategoryStream with priority NOTICE.
Definition Category.hh:387
log4shib::Category::removeAllAppenders
virtual void removeAllAppenders()
Removes all appenders for this Category.
Definition Category.cpp:149
log4shib::Category::alertStream
CategoryStream alertStream()
Return a CategoryStream with priority ALERT.
Definition Category.hh:507
log4shib::Category::errorStream
CategoryStream errorStream()
Return a CategoryStream with priority ERROR.
Definition Category.hh:447
log4shib::Category::getInstance
static Category & getInstance(const std::string &name)
Instantiate a Category with name name.
Definition Category.cpp:35
log4shib::Category::isDebugEnabled
bool isDebugEnabled() const
Return true if the Category will log messages with priority DEBUG.
Definition Category.hh:319
log4shib::Category::infoStream
CategoryStream infoStream()
Return a CategoryStream with priority INFO.
Definition Category.hh:357
log4shib::Category::getPriority
virtual Priority::Value getPriority() const
Returns the assigned Priority, if any, for this Category.
Definition Category.cpp:67
log4shib::Category::isPriorityEnabled
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
log4shib::Category::getCurrentCategories
static std::vector< Category * > * getCurrentCategories()
Returns all the currently defined categories as a vector of Category pointers.
Definition Category.cpp:43
log4shib::Category::isEmergEnabled
bool isEmergEnabled() const
Return true if the Category will log messages with priority EMERG.
Definition Category.hh:529
log4shib::Category::addAppender
virtual void addAppender(Appender *appender)
Adds an Appender to this Category.
Definition Category.cpp:93
log4shib::Category::isWarnEnabled
bool isWarnEnabled() const
Return true if the Category will log messages with priority WARN.
Definition Category.hh:409
log4shib::Category::getRootPriority
static Priority::Value getRootPriority()
Get the priority of the root Category.
Definition Category.cpp:31
log4shib::Category::fatalStream
CategoryStream fatalStream()
Return a CategoryStream with priority FATAL.
Definition Category.hh:575
log4shib::Category::shutdown
static void shutdown()
This method will remove all Appenders from Categories.XXX.
Definition Category.cpp:48
log4shib::Category::isErrorEnabled
bool isErrorEnabled() const
Return true if the Category will log messages with priority ERROR.
Definition Category.hh:439
log4shib::Category::setPriority
virtual void setPriority(Priority::Value priority)
Set the priority of this Category.
Definition Category.cpp:71
log4shib::Category::exists
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
log4shib::Category::isAlertEnabled
bool isAlertEnabled() const
Return true if the Category will log messages with priority ALERT.
Definition Category.hh:499
log4shib::Category::setAppender
void setAppender(Appender *appender)
Adds an Appender to this Category.
Definition Category.hh:165
log4shib::Category::getName
virtual const std::string & getName() const
Return the category name.
Definition Category.cpp:63
log4shib::Category::isInfoEnabled
bool isInfoEnabled() const
Return true if the Category will log messages with priority INFO.
Definition Category.hh:349
log4shib::Category::getAppender
virtual Appender * getAppender() const
Returns the first Appender for this Category, or NULL if no Appender has been set.
Definition Category.cpp:120
log4shib::Category::ownsAppender
bool ownsAppender() const
Returns true if the Category owns the first Appender in its Appender set.
Definition Category.hh:223
log4shib::Category::isCritEnabled
bool isCritEnabled() const
Return true if the Category will log messages with priority CRIT.
Definition Category.hh:469
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
std
Definition Portability.hh:37
log4shib::LoggingEvent
The internal representation of logging events.
Definition LoggingEvent.hh:32