Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
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
:
10
virtual
log4cpp::Filter::Decision
_decide
(
const
log4cpp::LoggingEvent
& event) {
11
log4cpp::Filter::Decision
decision =
log4cpp::Filter::NEUTRAL
;
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
:
26
TestFilter2
() {};
27
virtual
~TestFilter2
() {};
28
29
protected
:
30
virtual
log4cpp::Filter::Decision
_decide
(
const
log4cpp::LoggingEvent
& event) {
31
log4cpp::Filter::Decision
decision =
log4cpp::Filter::NEUTRAL
;
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
}
Filter.hh
TestFilter::TestFilter
TestFilter()
Definition:
testFilter.cpp:6
log4cpp::Filter::decide
virtual Decision decide(const LoggingEvent &event)
Definition:
Filter.cpp:50
log4cpp::Filter::setChainedFilter
virtual void setChainedFilter(Filter *filter)
Definition:
Filter.cpp:24
log4cpp::Priority::INFO
Definition:
Priority.hh:77
TestFilter
Definition:
testFilter.cpp:4
log4cpp::Filter::DENY
Definition:
Filter.hh:52
log4cpp::Filter
Definition:
Filter.hh:49
log4cpp::Filter::Decision
Decision
Definition:
Filter.hh:52
TestFilter2::_decide
virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent &event)
Definition:
testFilter.cpp:30
TestFilter::_decide
virtual log4cpp::Filter::Decision _decide(const log4cpp::LoggingEvent &event)
Definition:
testFilter.cpp:10
log4cpp::Filter::NEUTRAL
Definition:
Filter.hh:53
log4cpp::Filter::ACCEPT
Definition:
Filter.hh:54
main
int main(int argc, char **argv)
Definition:
testFilter.cpp:40
log4cpp::LoggingEvent
Definition:
LoggingEvent.hh:32
TestFilter2
Definition:
testFilter.cpp:24
TestFilter::~TestFilter
virtual ~TestFilter()
Definition:
testFilter.cpp:7
TestFilter2::~TestFilter2
virtual ~TestFilter2()
Definition:
testFilter.cpp:27
TestFilter2::TestFilter2
TestFilter2()
Definition:
testFilter.cpp:26
log4cpp::LoggingEvent::ndc
const std::string ndc
Definition:
LoggingEvent.hh:64
log4cpp::LoggingEvent::categoryName
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:14:17