OrocosComponentLibrary
2.7.0
|
00001 #include "logging/OstreamAppender.hpp" 00002 #include "ocl/Component.hpp" 00003 00004 #include <log4cpp/OstreamAppender.hh> 00005 00006 using namespace RTT; 00007 00008 namespace OCL { 00009 namespace logging { 00010 00011 OstreamAppender::OstreamAppender(std::string name) : 00012 OCL::logging::Appender(name), 00013 maxEventsPerCycle_prop("MaxEventsPerCycle", "Maximum number of log events to pop per cycle",1), 00014 maxEventsPerCycle(1) 00015 { 00016 properties()->addProperty(maxEventsPerCycle_prop); 00017 } 00018 00019 OstreamAppender::~OstreamAppender() 00020 { 00021 } 00022 00023 bool OstreamAppender::configureHook() 00024 { 00025 // verify valid limits 00026 int m = maxEventsPerCycle_prop.rvalue(); 00027 if ((0 > m)) 00028 { 00029 log(Error) << "Invalid maxEventsPerCycle value of " 00030 << m << ". Value must be >= 0." 00031 << endlog(); 00032 return false; 00033 } 00034 maxEventsPerCycle = m; 00035 00036 if (!appender) 00037 appender = new log4cpp::OstreamAppender(getName(), &std::cout); 00038 00039 return configureLayout(); 00040 } 00041 00042 void OstreamAppender::updateHook() 00043 { 00044 processEvents(1); 00045 } 00046 00047 void OstreamAppender::cleanupHook() 00048 { 00049 /* normally in log4cpp the category owns the appenders and deletes them 00050 itself, however we don't associate appenders and categories in the 00051 same manner. Hence, you have to manually manage appenders. 00052 */ 00053 delete appender; 00054 appender = 0; 00055 } 00056 00057 // namespaces 00058 } 00059 } 00060 00061 ORO_LIST_COMPONENT_TYPE(OCL::logging::OstreamAppender);