Apache log4cxx  Version 0.13.0
mapfilter.h
Go to the documentation of this file.
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 #ifndef _LOG4CXX_FILTER_MAPFILTER_H
18 #define _LOG4CXX_FILTER_MAPFILTER_H
19 
20 #include <log4cxx/spi/filter.h>
21 
22 #if defined(_MSC_VER)
23  #pragma warning ( push )
24  #pragma warning ( disable: 4251 )
25 #endif
26 
27 namespace log4cxx
28 {
29 namespace filter
30 {
31 
43 class LOG4CXX_EXPORT MapFilter: public log4cxx::spi::Filter
44 {
45  typedef std::map < LogString, LogString > KeyVals;
46 
47  private:
48  bool acceptOnMatch;
49  bool mustMatchAll; // true = AND; false = OR
50  KeyVals keyVals;
51 
52  public:
58 
59  MapFilter();
60 
64  virtual void setOption(const LogString& option,
65  const LogString& value);
66 
67  inline void setKeyValue(const LogString& strKey, const LogString& strValue)
68  {
69  this->keyVals[strKey] = strValue;
70  }
71 
72  inline const LogString& getValue(const LogString& strKey) const
73  {
74  static const LogString empty;
75  const KeyVals::const_iterator it(this->keyVals.find(strKey));
76 
77  return (it != keyVals.end() ? it->second : empty);
78  }
79 
80  inline void setAcceptOnMatch(bool acceptOnMatch1)
81  {
82  this->acceptOnMatch = acceptOnMatch1;
83  }
84 
85  inline bool getAcceptOnMatch() const
86  {
87  return acceptOnMatch;
88  }
89 
90  inline bool getMustMatchAll() const
91  {
92  return mustMatchAll;
93  }
94 
95  inline void setMustMatchAll(bool mustMatchAll1)
96  {
97  this->mustMatchAll = mustMatchAll1;
98  }
99 
104  FilterDecision decide(const spi::LoggingEventPtr& event) const;
105 }; // class MapFilter
106 
108 
109 } // namespace filter
110 } // namespace log4cxx
111 
112 #if defined(_MSC_VER)
113  #pragma warning (pop)
114 #endif
115 
116 #endif // _LOG4CXX_FILTER_MAPFILTER_H
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
void setMustMatchAll(bool mustMatchAll1)
Definition: mapfilter.h:95
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:37
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141
LOG4CXX_PTR_DEF(AndFilter)
FilterDecision
Definition: filter.h:87
bool getMustMatchAll() const
Definition: mapfilter.h:90
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
bool getAcceptOnMatch() const
Definition: mapfilter.h:85
void setAcceptOnMatch(bool acceptOnMatch1)
Definition: mapfilter.h:80
A Filter that operates on a Map and can be used like in the following example:
Definition: mapfilter.h:43
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:159
void setKeyValue(const LogString &strKey, const LogString &strValue)
Definition: mapfilter.h:67
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66
Users should extend this class to implement customized logging event filtering.
Definition: filter.h:68
const LogString & getValue(const LogString &strKey) const
Definition: mapfilter.h:72