log4cplus  2.1.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,
55  NEUTRAL,
59  ACCEPT
62  };
63 
64  // Forward Declarations
65  class Filter;
66  class InternalLoggingEvent;
67 
68 
75  const InternalLoggingEvent& event);
76 
78 
79 
108  : public virtual log4cplus::helpers::SharedObject
109  {
110  public:
111  // ctor and dtor
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:
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 
329  {
330  public:
331  // ctors
334 
338  virtual FilterResult decide(const InternalLoggingEvent& event) const;
339 
340  private:
341  // Methods
342  LOG4CPLUS_PRIVATE void init();
343 
344  // Data
346  bool acceptOnMatch;
348  bool neutralOnEmpty;
349  log4cplus::tstring ndcToMatch;
350  };
351 
375  {
376  public:
377  // ctors
380 
384  virtual FilterResult decide(const InternalLoggingEvent& event) const;
385 
386  private:
387  // Methods
388  LOG4CPLUS_PRIVATE void init();
389 
390  // Data
392  bool acceptOnMatch;
394  bool neutralOnEmpty;
396  log4cplus::tstring mdcKeyToMatch;
398  log4cplus::tstring mdcValueToMatch;
399  };
400 
401  } // end namespace spi
402 } // end namespace log4cplus
403 
404 #endif /* LOG4CPLUS_SPI_FILTER_HEADER_ */
This filter drops all logging events.
Definition: filter.h:150
DenyAllFilter(const log4cplus::helpers::Properties &)
virtual FilterResult decide(const InternalLoggingEvent &event) const
Always returns the DENY regardless of the InternalLoggingEvent parameter.
Users should extend this class to implement customized logging event filtering.
Definition: filter.h:109
virtual FilterResult decide(const InternalLoggingEvent &event) const =0
If the decision is DENY, then the event will be dropped.
void appendFilter(FilterPtr filter)
Appends filter to the end of this filter chain.
FilterPtr next
Points to the next filter in the filter chain.
Definition: filter.h:137
This filter allows using std::function<FilterResult(const InternalLoggingEvent &)>.
Definition: filter.h:290
std::function< FilterResult(const InternalLoggingEvent &)> Function
Definition: filter.h:293
virtual FilterResult decide(const InternalLoggingEvent &) const
Returns result returned by function.
The internal representation of logging events.
Definition: loggingevent.h:51
This is a very simple filter based on LogLevel matching.
Definition: filter.h:174
LogLevelMatchFilter(const log4cplus::helpers::Properties &p)
virtual FilterResult decide(const InternalLoggingEvent &event) const
Return the decision of this filter.
This is a very simple filter based on LogLevel matching, which can be used to reject messages with Lo...
Definition: filter.h:228
virtual FilterResult decide(const InternalLoggingEvent &event) const
Return the decision of this filter.
LogLevelRangeFilter(const log4cplus::helpers::Properties &p)
This is a simple filter based on the key/value pair stored in MDC.
Definition: filter.h:375
virtual FilterResult decide(const InternalLoggingEvent &event) const
Returns NEUTRAL is there is no string match.
MDCMatchFilter(const log4cplus::helpers::Properties &p)
This is a simple filter based on the string returned by event.getNDC().
Definition: filter.h:329
virtual FilterResult decide(const InternalLoggingEvent &event) const
Returns NEUTRAL is there is no string match.
NDCMatchFilter(const log4cplus::helpers::Properties &p)
This is a very simple filter based on string matching.
Definition: filter.h:263
virtual FilterResult decide(const InternalLoggingEvent &event) const
Returns NEUTRAL is there is no string match.
StringMatchFilter(const log4cplus::helpers::Properties &p)
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
This header defines the LogLevel type.
@ ACCEPT
The log event must be logged immediately without consulting with the remaining filters,...
Definition: filter.h:59
@ DENY
The log event must be dropped immediately without consulting with the remaining filters,...
Definition: filter.h:52
@ NEUTRAL
This filter is neutral with respect to the log event; the remaining filters, if if any,...
Definition: filter.h:55
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
std::basic_string< tchar > tstring
Definition: tstring.h:39
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
#define LOG4CPLUS_EXPORT
Definition: win32.h:141