Hey dudes,

I am trying to implement a custom filter using log4cxx.  I have subclassed Filter and implemented a decide() method.  However, when I try to execute my program, log4cxx complains that my filter class cannot be found.  Am I missing a step?  Do I need to use one of the macros defined in object.h like DECLARE_LOG4CXX_OBJECT()? 

The output of my program is:

log4cxx: Could not instantiate class [FooFilter].
log4cxx: Class not found: FooFilter



Excerpts from my code is below.

I would appreciate any help on this.

Thanks

>>> contents of foofilter.h >>>

#if !defined(AFX_FOOFILTER_H__94B10DBB_D815_4D44_8F8A_423493A9F473__INCLUDED_)
#define AFX_FOOFILTER_H__94B10DBB_D815_4D44_8F8A_423493A9F473__INCLUDED_

#include <log4cxx/spi/filter.h>

using namespace log4cxx;
using namespace log4cxx::spi;

class FooFilter : public spi::Filter 
{
public:

  FooFilter();
  FilterDecision decide(const LoggingEventPtr& event) const;

};

#endif

>>> contents of FooFilter.cpp >>>

#include <iostream>
#include <log4cxx/spi/filter.h>
#include <log4cxx/spi/loggingevent.h>
#include "FooFilter.h"

using namespace log4cxx;
using namespace log4cxx::spi;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

FooFilter::FooFilter(){
  std::cout << "FooFilter: constructing.";
}


Filter::FilterDecision FooFilter::decide(
   const spi::LoggingEventPtr& event) const {

  std::cout << "FooFilter: deciding now.";

  return Filter::ACCEPT;
}

>>> contents of log4j.xml >>>

<?xml version="1.0" encoding="UTF-8" ?>

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
       
  <appender name="apple" class="org.apache.log4j.FileAppender">
    <param name="File" value="logs/apple.log"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.SimpleLayout"/>
    <filter class="FooFilter"/>
  </appender>

  <root>
    <priority value ="debug"/>
    <appender-ref ref="apple"/>
  </root>

</log4j:configuration>

Reply via email to