testFilter.cpp
Go to the documentation of this file.
00001 #include <log4cpp/Filter.hh>
00002 #include <iostream>
00003 
00004 class TestFilter : public log4cpp::Filter {
00005     public:
00006     TestFilter() {};
00007     virtual ~TestFilter() {};
00008 
00009     protected:
00010     virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent& event) {
00011         log4cpp::Filter::Decision decision = log4cpp::Filter::NEUTRAL;
00012 
00013         if (event.categoryName == "deny")
00014             decision = log4cpp::Filter::DENY;
00015         
00016         if (event.categoryName == "accept")
00017             decision = log4cpp::Filter::ACCEPT;
00018 
00019         return decision;
00020     };
00021 };
00022 
00023 
00024 class TestFilter2 : public log4cpp::Filter {
00025     public:
00026     TestFilter2() {};
00027     virtual ~TestFilter2() {};
00028 
00029     protected:
00030     virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent& event) {
00031         log4cpp::Filter::Decision decision = log4cpp::Filter::NEUTRAL;
00032 
00033         if (event.ndc == "test")
00034             decision = log4cpp::Filter::DENY;
00035         
00036         return decision;
00037     };
00038 };
00039 
00040 int main(int argc, char** argv) {
00041     TestFilter filter;
00042 
00043     bool resultsOK = true;
00044     
00045     std::cout << "decision 1 (should be 1): " << filter.decide(log4cpp::LoggingEvent("accept", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
00046 
00047     std::cout << "decision 2 (should be -1): " << filter.decide(log4cpp::LoggingEvent("deny", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
00048 
00049     std::cout << "decision 3 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
00050 
00051     std::cout << "decision 4 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "test", log4cpp::Priority::INFO)) << std::endl;
00052 
00053     filter.setChainedFilter(new TestFilter2());
00054     
00055     std::cout << "decision 5 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
00056 
00057     std::cout << "decision 6 (should be -1): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "test", log4cpp::Priority::INFO)) << std::endl;
00058 
00059     return 0;
00060 }


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sat Jun 8 2019 18:45:46