00001 #ifndef CATEGORY_HPP 00002 #define CATEGORY_HPP 1 00003 00004 #include <log4cpp/Category.hh> 00005 #include "LoggingEvent.hpp" 00006 #include "CategoryStream.hpp" 00007 #include <rtt/Port.hpp> 00008 00009 // forward declare 00010 namespace RTT { 00011 class ConnPolicy; 00012 } 00013 00014 namespace OCL { 00015 namespace logging { 00016 00017 // forward declare 00018 class LoggingService; 00019 00025 class Category : public log4cpp::Category 00026 { 00027 public: 00028 virtual ~Category(); 00029 00030 // custom real-time versions - available to user 00031 // these replace std::string versions in the base class 00032 public: 00033 virtual void log(log4cpp::Priority::Value priority, 00034 const RTT::rt_string& message) throw(); 00035 void debug(const RTT::rt_string& message) throw(); 00036 void info(const RTT::rt_string& message) throw(); 00037 void notice(const RTT::rt_string& message) throw(); 00038 void warn(const RTT::rt_string& message) throw(); 00039 void error(const RTT::rt_string& message) throw(); 00040 void crit(const RTT::rt_string& message) throw(); 00041 void alert(const RTT::rt_string& message) throw(); 00042 void emerg(const RTT::rt_string& message) throw(); 00043 void fatal(const RTT::rt_string& message) throw(); 00044 00049 CategoryStream getRTStream(log4cpp::Priority::Value priority); 00050 00051 protected: 00052 void _logUnconditionally2(log4cpp::Priority::Value priority, 00053 const RTT::rt_string& message) throw(); 00054 00055 00056 // real-time - available to user 00057 public: 00058 using log4cpp::Category::setPriority; 00059 using log4cpp::Category::getPriority; 00060 using log4cpp::Category::getChainedPriority; 00061 using log4cpp::Category::isPriorityEnabled; 00062 00063 using log4cpp::Category::setAdditivity; 00064 using log4cpp::Category::getAdditivity; 00065 using log4cpp::Category::getParent; 00066 00067 using log4cpp::Category::isDebugEnabled; 00068 using log4cpp::Category::isInfoEnabled; 00069 using log4cpp::Category::isNoticeEnabled; 00070 using log4cpp::Category::isWarnEnabled; 00071 using log4cpp::Category::isErrorEnabled; 00072 using log4cpp::Category::isCritEnabled; 00073 using log4cpp::Category::isAlertEnabled; 00074 using log4cpp::Category::isEmergEnabled; 00075 using log4cpp::Category::isFatalEnabled; 00076 00077 00078 // real-time (but uses locking) - available to user but BEWARE locking! 00079 public: 00080 using log4cpp::Category::getAppender; 00081 00082 00083 00084 // NOT real-time and so _NOT_ available to user 00085 protected: 00086 using log4cpp::Category::getRoot; 00087 using log4cpp::Category::setRootPriority; 00088 using log4cpp::Category::getRootPriority; 00089 using log4cpp::Category::getInstance; 00090 using log4cpp::Category::exists; 00091 using log4cpp::Category::getCurrentCategories; 00092 using log4cpp::Category::shutdown; 00093 using log4cpp::Category::getName; 00094 00095 using log4cpp::Category::removeAllAppenders; 00096 using log4cpp::Category::removeAppender; 00097 using log4cpp::Category::addAppender; 00098 using log4cpp::Category::setAppender; 00099 00100 using log4cpp::Category::getAllAppenders; 00101 00102 using log4cpp::Category::debugStream; 00103 using log4cpp::Category::infoStream; 00104 using log4cpp::Category::noticeStream; 00105 using log4cpp::Category::warnStream; 00106 using log4cpp::Category::errorStream; 00107 using log4cpp::Category::critStream; 00108 using log4cpp::Category::emergStream; 00109 using log4cpp::Category::fatalStream; 00110 using log4cpp::Category::getStream; 00111 using log4cpp::Category::operator<<; 00112 00113 using log4cpp::Category::callAppenders; 00114 00115 using log4cpp::Category::log; 00116 using log4cpp::Category::logva; 00117 using log4cpp::Category::debug; 00118 using log4cpp::Category::info; 00119 using log4cpp::Category::notice; 00120 using log4cpp::Category::warn; 00121 using log4cpp::Category::error; 00122 using log4cpp::Category::crit; 00123 using log4cpp::Category::alert; 00124 using log4cpp::Category::emerg; 00125 using log4cpp::Category::fatal; 00126 00127 using log4cpp::Category::_logUnconditionally; 00128 using log4cpp::Category::_logUnconditionally2; 00129 00130 00131 protected: 00132 Category(const std::string& name, 00133 log4cpp::Category* parent, 00134 log4cpp::Priority::Value priority = log4cpp::Priority::NOTSET); 00135 00136 protected: 00141 virtual void callAppenders(const OCL::logging::LoggingEvent& event) throw(); 00142 00147 static std::string convertName(const std::string& name); 00148 00149 public: 00155 static log4cpp::Category* createOCLCategory(const std::string& name, 00156 log4cpp::Category* parent, 00157 log4cpp::Priority::Value priority); 00158 00159 00160 protected: 00161 //protected: 00162 RTT::OutputPort<OCL::logging::LoggingEvent> log_port; 00164 friend class OCL::logging::LoggingService; 00165 00166 public: 00172 bool connectToLogPort(RTT::base::PortInterface& otherPort); 00178 bool connectToLogPort(RTT::base::PortInterface& otherPort, 00179 RTT::ConnPolicy& cp); 00180 00181 private: 00182 /* prevent copying and assignment */ 00183 Category(const Category& other); 00184 Category& operator=(const Category& other); 00185 }; 00186 00187 // namespaces 00188 } 00189 } 00190 00191 #endif