OstreamAppender.cpp
Go to the documentation of this file.
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     if (!log_port.connected()) return;      // no category connected to us
00045 
00046     /* Consume waiting events until
00047        a) the buffer is empty
00048        b) we consume too many events on one cycle
00049      */
00050     OCL::logging::LoggingEvent   event;
00051     assert(appender);
00052     assert(0 <= maxEventsPerCycle);
00053     if (0 == maxEventsPerCycle)
00054     {
00055         // consume infinite events
00056         for (;;)
00057         {
00058             if (log_port.read( event ) == NewData)
00059             {
00060                 log4cpp::LoggingEvent   e2 = event.toLog4cpp();
00061                 appender->doAppend(e2);
00062             }
00063             else
00064             {
00065                 break;      // nothing to do
00066             }
00067         }
00068     }
00069     else
00070     {
00071 
00072         // consume up to maxEventsPerCycle events
00073         int n       = maxEventsPerCycle;
00074         do
00075         {
00076             if (log_port.read( event ) == NewData)
00077             {
00078                 log4cpp::LoggingEvent   e2 = event.toLog4cpp();
00079                 appender->doAppend(e2);
00080             }
00081             else
00082             {
00083                 break;      // nothing to do
00084             }
00085             --n;
00086         }
00087         while (0 < n);
00088     }
00089 }
00090 
00091 void OstreamAppender::cleanupHook()
00092 {
00093     delete appender;
00094     appender = 0;
00095 }
00096 
00097 // namespaces
00098 }
00099 }
00100 
00101 ORO_LIST_COMPONENT_TYPE(OCL::logging::OstreamAppender);


ocl
Author(s): OCL Development Team
autogenerated on Thu Jan 2 2014 11:38:08