GenerationalFileAppender.cpp
Go to the documentation of this file.
00001 #include "logging/GenerationalFileAppender.hpp"
00002 #include "ocl/Component.hpp"
00003 #include <rtt/Logger.hpp>
00004 
00005 #include <log4cpp/GenerationalFileAppender.hh>
00006 
00007 using namespace RTT;
00008 
00009 namespace OCL {
00010 namespace logging {
00011 
00012 GenerationalFileAppender::GenerationalFileAppender(std::string name) :
00013     OCL::logging::Appender(name),
00014     advanceGeneration_op("advanceGeneration", &GenerationalFileAppender::advanceGeneration, this, RTT::OwnThread),
00015     filename_prop("Filename", "Name of file to log to"),
00016     maxEventsPerCycle_prop("MaxEventsPerCycle",
00017                            "Maximum number of log events to pop per cycle",
00018                            1),
00019     maxEventsPerCycle(1)
00020 {
00021         provides()->addOperation(advanceGeneration_op).doc("Advance to the next logfile generation");
00022 
00023     properties()->addProperty(filename_prop);
00024     properties()->addProperty(maxEventsPerCycle_prop);
00025 }
00026 
00027 GenerationalFileAppender::~GenerationalFileAppender()
00028 {
00029 }
00030 
00031 bool GenerationalFileAppender::configureHook()
00032 {
00033     // verify valid limits
00034     int m = maxEventsPerCycle_prop.rvalue();
00035     if ((0 > m))
00036     {
00037         log(Error) << "Invalid maxEventsPerCycle value of "
00038                    << m << ". Value must be >= 0."
00039                    << endlog();
00040         return false;
00041     }
00042     maxEventsPerCycle = m;
00043 
00044     // \todo error checking
00045 
00046     appender = new log4cpp::GenerationalFileAppender(getName(),
00047                                                                                                          filename_prop.get());
00048 
00049     return configureLayout();
00050 }
00051 
00052 void GenerationalFileAppender::updateHook()
00053 {
00054         processEvents(maxEventsPerCycle);
00055 }
00056 
00057 void GenerationalFileAppender::cleanupHook()
00058 {
00059     /* normally in log4cpp the category owns the appenders and deletes them
00060        itself, however we don't associate appenders and categories in the
00061        same manner. Hence, you have to manually manage appenders.
00062     */
00063     delete appender;
00064     appender = 0;
00065 }
00066 
00067 void GenerationalFileAppender::advanceGeneration()
00068 {
00069         if (0 != appender)
00070         {
00071                 static_cast<log4cpp::GenerationalFileAppender*>(appender)->advanceGeneration();
00072         }
00073         else
00074         {
00075                 log(Error) << "No appender to roll over!" << endlog();
00076         }
00077 }
00078 
00079 // namespaces
00080 }
00081 }
00082 
00083 ORO_LIST_COMPONENT_TYPE(OCL::logging::GenerationalFileAppender);


ocl
Author(s): OCL Development Team
autogenerated on Sun Nov 27 2016 03:45:30