-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestFilter.cpp
More file actions
60 lines (40 loc) · 1.9 KB
/
Copy pathtestFilter.cpp
File metadata and controls
60 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <log4cpp/Filter.hh>
#include <iostream>
class TestFilter : public log4cpp::Filter {
public:
TestFilter() {};
virtual ~TestFilter() {};
protected:
virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent& event) {
log4cpp::Filter::Decision decision = log4cpp::Filter::NEUTRAL;
if (event.categoryName == "deny")
decision = log4cpp::Filter::DENY;
if (event.categoryName == "accept")
decision = log4cpp::Filter::ACCEPT;
return decision;
};
};
class TestFilter2 : public log4cpp::Filter {
public:
TestFilter2() {};
virtual ~TestFilter2() {};
protected:
virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent& event) {
log4cpp::Filter::Decision decision = log4cpp::Filter::NEUTRAL;
if (event.ndc == "test")
decision = log4cpp::Filter::DENY;
return decision;
};
};
int main(int argc, char** argv) {
TestFilter filter;
bool resultsOK = true;
std::cout << "decision 1 (should be 1): " << filter.decide(log4cpp::LoggingEvent("accept", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
std::cout << "decision 2 (should be -1): " << filter.decide(log4cpp::LoggingEvent("deny", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
std::cout << "decision 3 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
std::cout << "decision 4 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "test", log4cpp::Priority::INFO)) << std::endl;
filter.setChainedFilter(new TestFilter2());
std::cout << "decision 5 (should be 0): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "ndc", log4cpp::Priority::INFO)) << std::endl;
std::cout << "decision 6 (should be -1): " << filter.decide(log4cpp::LoggingEvent("neither", "bla", "test", log4cpp::Priority::INFO)) << std::endl;
return 0;
}