log4cplus  2.0.0
filter.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: filter.h
4 // Created: 5/2003
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 1999-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
25 #ifndef LOG4CPLUS_SPI_FILTER_HEADER_
26 #define LOG4CPLUS_SPI_FILTER_HEADER_
27 
28 #include <log4cplus/config.hxx>
29 
30 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
31 #pragma once
32 #endif
33 
34 #include <functional>
35 
37 #include <log4cplus/loglevel.h>
38 
39 
40 namespace log4cplus {
41 
42  namespace helpers
43  {
44 
45  class Properties;
46 
47  }
48 
49  namespace spi {
50 
51 
52  enum FilterResult { DENY,
62  };
63 
64  // Forward Declarations
65  class Filter;
66  class InternalLoggingEvent;
67 
68 
74  LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter* filter,
75  const InternalLoggingEvent& event);
76 
78 
79 
108  : public virtual log4cplus::helpers::SharedObject
109  {
110  public:
111  // ctor and dtor
112  Filter();
113  virtual ~Filter();
114 
115  // Methods
119  void appendFilter(FilterPtr filter);
120 
131  virtual FilterResult decide(const InternalLoggingEvent& event) const = 0;
132 
133  // Data
138  };
139 
140 
141 
151  public:
152  DenyAllFilter ();
154 
159  virtual FilterResult decide(const InternalLoggingEvent& event) const;
160  };
161 
162 
175  public:
178 
189  virtual FilterResult decide(const InternalLoggingEvent& event) const;
190 
191  private:
192  // Methods
193  LOG4CPLUS_PRIVATE void init();
194 
195  // Data
197  bool acceptOnMatch;
198  LogLevel logLevelToMatch;
199  };
200 
201 
202 
229  public:
230  // ctors
233 
237  virtual FilterResult decide(const InternalLoggingEvent& event) const;
238 
239  private:
240  // Methods
241  LOG4CPLUS_PRIVATE void init();
242 
243  // Data
245  bool acceptOnMatch;
246  LogLevel logLevelMin;
247  LogLevel logLevelMax;
248  };
249 
250 
251 
264  public:
265  // ctors
268 
272  virtual FilterResult decide(const InternalLoggingEvent& event) const;
273 
274  private:
275  // Methods
276  LOG4CPLUS_PRIVATE void init();
277 
278  // Data
280  bool acceptOnMatch;
281  log4cplus::tstring stringToMatch;
282  };
283 
289  : public Filter
290  {
291  public:
292  typedef std::function<FilterResult (const InternalLoggingEvent &)>
294 
296 
300  virtual FilterResult decide(const InternalLoggingEvent&) const;
301 
302  private:
303  Function function;
304  };
305 
306  } // end namespace spi
307 } // end namespace log4cplus
308 
309 #endif /* LOG4CPLUS_SPI_FILTER_HEADER_ */
This is a very simple filter based on LogLevel matching, which can be used to reject messages with Lo...
Definition: filter.h:228
This filter drops all logging events.
Definition: filter.h:150
The internal representation of logging events.
Definition: loggingevent.h:51
Users should extend this class to implement customized logging event filtering.
Definition: filter.h:107
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter *filter, const InternalLoggingEvent &event)
This method is used to filter an InternalLoggingEvent.
helpers::SharedObjectPtr< Filter > FilterPtr
Definition: filter.h:77
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
This filter is neutral with respect to the log event; the remaining filters, if if any,...
Definition: filter.h:55
std::basic_string< tchar > tstring
Definition: tstring.h:39
FilterPtr next
Points to the next filter in the filter chain.
Definition: filter.h:137
This header defines the LogLevel type.
This is a very simple filter based on LogLevel matching.
Definition: filter.h:174
The log event must be logged immediately without consulting with the remaining filters,...
Definition: filter.h:59
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
This is a very simple filter based on string matching.
Definition: filter.h:263
std::function< FilterResult(const InternalLoggingEvent &)> Function
Definition: filter.h:293
The log event must be dropped immediately without consulting with the remaining filters,...
Definition: filter.h:52
This filter allows using std::function<FilterResult(const InternalLoggingEvent &)>.
Definition: filter.h:288