Accessing log4cxx object initiailized in configuartion file

193 Views Asked by At

New to log4cxx. I have a configuration file where I define the log4cxx configuration. That works fine. What I want to do now is access an object defined in that config file and extend it's functionality, e.g.

say I have a Log4Cxx implementation that has a Rolling File Appender. What I ultimately want to to do is be able to add triggers to that Appender in the cpp file, to be able to trigger a rollover.
********* log4cxx.xml *********************

..
..
<appender name="rfa" class="org.apachelog4j.rolling.RollingFileAppender">
   <rollingPolicy class="org.apache.log4j.rolling.rollingPolicy">
     <param name="file" value="logfiles/logfile%d{yyyy-MM-dd}.txt" /> 
   </rollingPolicy>
   <triggeringPolicy
      class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
      <param name="MaxFileSize" value="10MB"
   </triggeringPolicy>
</appender>

My question is

  1. How can I modify/add to this appender in the code file. What I've been trying is something like

*********LogImplementation.cpp ******* '''

#include "LogImplementation.h"
.. 
#include "log4cxx/rolling/rollingpolicy.h"
#include "log4cxx/rolling/rollingfileappender.h"
#include "log4cxx/rolling/filterbasedtriggeringpolicy.h"
#include "log4cxx/helpers/pool.h"
#include "log4cxx/spi/filter.h"
#include "log4cxx/rolling/rollingpolicy.h"
#include "log4cxx/logger.h"

using namespace log4cxx;
using namespace log4cxx::rolling;
using namespace log4cxx::helpers; 
 ..

void LogImplemetation::addFilter()
{
    FilterBasedTriggeringPolicyPtr fbtp = FilterBasedTriggeringPolicyPtr(new FilterBasedTriggeringPolicy());
 
    log4cxx::filter::StringMatchFilter tf;
    tf.setStringToMatch("filterText");
    tf.setAcceptOnMatch(true);

    fbtp->addFilter(&tf);

    Pool p;
    fbtp->activateOptions(p); 
    rfa->setTriggeringPolicy(fbtp);

}

'''

but I'm getting a compilation error because it doesn't recognize "rfa" as an rolling file appender object. I also tried

log4cxx::Appender.rfs->setTriggeringPolicy(fbtp); but I get an "unqualified id before '.' token" compilation error in that case.

0

There are 0 best solutions below