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


ocl
Author(s): OCL Development Team
autogenerated on Sat Jun 8 2019 18:48:54