testFilter.cpp
Go to the documentation of this file.
1 #include <log4cpp/Filter.hh>
2 #include <iostream>
3 
4 class TestFilter : public log4cpp::Filter {
5  public:
6  TestFilter() {};
7  virtual ~TestFilter() {};
8 
9  protected:
12 
13  if (event.categoryName == "deny")
14  decision = log4cpp::Filter::DENY;
15 
16  if (event.categoryName == "accept")
17  decision = log4cpp::Filter::ACCEPT;
18 
19  return decision;
20  };
21 };
22 
23 
24 class TestFilter2 : public log4cpp::Filter {
25  public:
27  virtual ~TestFilter2() {};
28 
29  protected:
32 
33  if (event.ndc == "test")
34  decision = log4cpp::Filter::DENY;
35 
36  return decision;
37  };
38 };
39 
40 int main(int argc, char** argv) {
41  TestFilter filter;
42 
43  bool resultsOK = true;
44 
45  std::cout << "decision 1 (should be 1): " << filter.decide(log4cpp::LoggingEvent("accept", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
46 
47  std::cout << "decision 2 (should be -1): " << filter.decide(log4cpp::LoggingEvent("deny", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
48 
49  std::cout << "decision 3 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
50 
51  std::cout << "decision 4 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "test", log4cpp::Priority::INFO)) << std::endl;
52 
53  filter.setChainedFilter(new TestFilter2());
54 
55  std::cout << "decision 5 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
56 
57  std::cout << "decision 6 (should be -1): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "test", log4cpp::Priority::INFO)) << std::endl;
58 
59  return 0;
60 }
virtual Decision decide(const LoggingEvent &event)
Definition: Filter.cpp:50
virtual void setChainedFilter(Filter *filter)
Definition: Filter.cpp:24
virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent &event)
Definition: testFilter.cpp:30
virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent &event)
Definition: testFilter.cpp:10
int main(int argc, char **argv)
Definition: testFilter.cpp:40
virtual ~TestFilter()
Definition: testFilter.cpp:7
virtual ~TestFilter2()
Definition: testFilter.cpp:27
const std::string ndc
Definition: LoggingEvent.hh:64
const std::string categoryName
Definition: LoggingEvent.hh:58


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00