1 | /*
|
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
3 | * contributor license agreements. See the NOTICE file distributed with
|
---|
4 | * this work for additional information regarding copyright ownership.
|
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
6 | * (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | *
|
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | *
|
---|
11 | * Unless required by applicable law or agreed to in writing, software
|
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | * See the License for the specific language governing permissions and
|
---|
15 | * limitations under the License.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef _LOG4CXX_FILTER_LEVEL_RANGE_FILTER_H
|
---|
19 | #define _LOG4CXX_FILTER_LEVEL_RANGE_FILTER_H
|
---|
20 |
|
---|
21 | #include <log4cxx/spi/filter.h>
|
---|
22 | #include <log4cxx/level.h>
|
---|
23 |
|
---|
24 | namespace log4cxx
|
---|
25 | {
|
---|
26 | namespace filter
|
---|
27 | {
|
---|
28 | /**
|
---|
29 | This is a very simple filter based on level matching, which can be
|
---|
30 | used to reject messages with priorities outside a certain range.
|
---|
31 |
|
---|
32 | <p>The filter admits three options <b>LevelMin</b>, <b>LevelMax</b>
|
---|
33 | and <b>AcceptOnMatch</b>.
|
---|
34 |
|
---|
35 | <p>If the level of the {@link spi::LoggingEvent LoggingEvent} is not
|
---|
36 | between Min and Max (inclusive), then {@link spi::Filter#DENY DENY}
|
---|
37 | is returned.
|
---|
38 |
|
---|
39 | <p> If the Logging event level is within the specified range, then if
|
---|
40 | <b>AcceptOnMatch</b> is true, {@link spi::Filter#ACCEPT ACCEPT} is
|
---|
41 | returned, and if <b>AcceptOnMatch</b> is false,
|
---|
42 | {@link spi::Filter#NEUTRAL NEUTRAL} is returned.
|
---|
43 |
|
---|
44 | <p>If <code>LevelMin</code>w is not defined, then there is no
|
---|
45 | minimum acceptable level (ie a level is never rejected for
|
---|
46 | being too "low"/unimportant). If <code>LevelMax</code> is not
|
---|
47 | defined, then there is no maximum acceptable level (ie a
|
---|
48 | level is never rejected for beeing too "high"/important).
|
---|
49 |
|
---|
50 | <p>Refer to the {@link
|
---|
51 | AppenderSkeleton#setThreshold setThreshold} method
|
---|
52 | available to <code>all</code> appenders extending
|
---|
53 | AppenderSkeleton for a more convenient way to
|
---|
54 | filter out events by level.
|
---|
55 | */
|
---|
56 |
|
---|
57 | class LOG4CXX_EXPORT LevelRangeFilter : public spi::Filter
|
---|
58 | {
|
---|
59 | private:
|
---|
60 | /**
|
---|
61 | Do we return ACCEPT when a match occurs. Default is
|
---|
62 | <code>false</code>, so that later filters get run by default
|
---|
63 | */
|
---|
64 | bool acceptOnMatch;
|
---|
65 | LevelPtr levelMin;
|
---|
66 | LevelPtr levelMax;
|
---|
67 |
|
---|
68 | public:
|
---|
69 | typedef spi::Filter BASE_CLASS;
|
---|
70 | DECLARE_LOG4CXX_OBJECT(LevelRangeFilter)
|
---|
71 | BEGIN_LOG4CXX_CAST_MAP()
|
---|
72 | LOG4CXX_CAST_ENTRY(LevelRangeFilter)
|
---|
73 | LOG4CXX_CAST_ENTRY_CHAIN(BASE_CLASS)
|
---|
74 | END_LOG4CXX_CAST_MAP()
|
---|
75 |
|
---|
76 | LevelRangeFilter();
|
---|
77 |
|
---|
78 | /**
|
---|
79 | Set options
|
---|
80 | */
|
---|
81 | virtual void setOption(const LogString& option,
|
---|
82 | const LogString& value);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | Set the <code>LevelMin</code> option.
|
---|
86 | */
|
---|
87 | void setLevelMin(const LevelPtr& levelMin1)
|
---|
88 | { this->levelMin = levelMin1; }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | Get the value of the <code>LevelMin</code> option.
|
---|
92 | */
|
---|
93 | const LevelPtr& getLevelMin() const
|
---|
94 | { return levelMin; }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | Set the <code>LevelMax</code> option.
|
---|
98 | */
|
---|
99 | void setLevelMax(const LevelPtr& levelMax1)
|
---|
100 | { this->levelMax = levelMax1; }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | Get the value of the <code>LevelMax</code> option.
|
---|
104 | */
|
---|
105 | const LevelPtr& getLevelMax() const
|
---|
106 | { return levelMax; }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | Set the <code>AcceptOnMatch</code> option.
|
---|
110 | */
|
---|
111 | inline void setAcceptOnMatch(bool acceptOnMatch1)
|
---|
112 | { this->acceptOnMatch = acceptOnMatch1; }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | Get the value of the <code>AcceptOnMatch</code> option.
|
---|
116 | */
|
---|
117 | inline bool getAcceptOnMatch() const
|
---|
118 | { return acceptOnMatch; }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | Return the decision of this filter.
|
---|
122 |
|
---|
123 | Returns {@link spi::Filter#NEUTRAL NEUTRAL} if the
|
---|
124 | <b>LevelToMatch</b> option is not set or if there is not match.
|
---|
125 | Otherwise, if there is a match, then the returned decision is
|
---|
126 | {@link spi::Filter#ACCEPT ACCEPT} if the
|
---|
127 | <b>AcceptOnMatch</b> property is set to <code>true</code>. The
|
---|
128 | returned decision is {@link spi::Filter#DENY DENY} if the
|
---|
129 | <b>AcceptOnMatch</b> property is set to false.
|
---|
130 | */
|
---|
131 | FilterDecision decide(const spi::LoggingEventPtr& event) const;
|
---|
132 | }; // class LevelRangeFilter
|
---|
133 | LOG4CXX_PTR_DEF(LevelRangeFilter);
|
---|
134 | } // namespace filter
|
---|
135 | } // namespace log4cxx
|
---|
136 |
|
---|
137 | #endif // _LOG4CXX_FILTER_LEVEL_RANGE_FILTER_H
|
---|