log4cplus  2.0.0
filter.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    filter.h
00004 // Created: 5/2003
00005 // Author:  Tad E. Smith
00006 //
00007 //
00008 // Copyright 1999-2015 Tad E. Smith
00009 //
00010 // Licensed under the Apache License, Version 2.0 (the "License");
00011 // you may not use this file except in compliance with the License.
00012 // You may obtain a copy of the License at
00013 //
00014 //     http://www.apache.org/licenses/LICENSE-2.0
00015 //
00016 // Unless required by applicable law or agreed to in writing, software
00017 // distributed under the License is distributed on an "AS IS" BASIS,
00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 // See the License for the specific language governing permissions and
00020 // limitations under the License.
00021 
00025 #ifndef LOG4CPLUS_SPI_FILTER_HEADER_
00026 #define LOG4CPLUS_SPI_FILTER_HEADER_
00027 
00028 #include <log4cplus/config.hxx>
00029 
00030 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00031 #pragma once
00032 #endif
00033 
00034 #include <functional>
00035 
00036 #include <log4cplus/helpers/pointer.h>
00037 #include <log4cplus/loglevel.h>
00038 
00039 
00040 namespace log4cplus {
00041 
00042     namespace helpers
00043     {
00044 
00045         class Properties;
00046 
00047     }
00048 
00049     namespace spi {
00050 
00051 
00052         enum FilterResult { DENY, 
00055                             NEUTRAL, 
00059                             ACCEPT 
00062                           };
00063 
00064         // Forward Declarations
00065         class Filter;
00066         class InternalLoggingEvent;
00067 
00068 
00074         LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter* filter,
00075                                                   const InternalLoggingEvent& event);
00076 
00077         typedef helpers::SharedObjectPtr<Filter> FilterPtr;
00078 
00079 
00107         class LOG4CPLUS_EXPORT Filter
00108             : public virtual log4cplus::helpers::SharedObject
00109         {
00110         public:
00111           // ctor and dtor
00112             Filter();
00113             virtual ~Filter();
00114 
00115           // Methods
00119             void appendFilter(FilterPtr filter);
00120 
00131             virtual FilterResult decide(const InternalLoggingEvent& event) const = 0;
00132 
00133           // Data
00137             FilterPtr next;
00138         };
00139 
00140 
00141 
00150         class LOG4CPLUS_EXPORT DenyAllFilter : public Filter {
00151         public:
00152             DenyAllFilter ();
00153             DenyAllFilter (const log4cplus::helpers::Properties&);
00154 
00159             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00160         };
00161 
00162 
00174         class LOG4CPLUS_EXPORT LogLevelMatchFilter : public Filter {
00175         public:
00176             LogLevelMatchFilter();
00177             LogLevelMatchFilter(const log4cplus::helpers::Properties& p);
00178 
00189             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00190 
00191         private:
00192           // Methods
00193             LOG4CPLUS_PRIVATE void init();
00194 
00195           // Data
00197             bool acceptOnMatch;
00198             LogLevel logLevelToMatch;
00199         };
00200 
00201 
00202 
00228         class LOG4CPLUS_EXPORT LogLevelRangeFilter : public Filter {
00229         public:
00230           // ctors
00231             LogLevelRangeFilter();
00232             LogLevelRangeFilter(const log4cplus::helpers::Properties& p);
00233 
00237             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00238 
00239         private:
00240           // Methods
00241             LOG4CPLUS_PRIVATE void init();
00242 
00243           // Data
00245             bool acceptOnMatch;
00246             LogLevel logLevelMin;
00247             LogLevel logLevelMax;
00248         };
00249 
00250 
00251 
00263         class LOG4CPLUS_EXPORT StringMatchFilter : public Filter {
00264         public:
00265           // ctors
00266             StringMatchFilter();
00267             StringMatchFilter(const log4cplus::helpers::Properties& p);
00268 
00272             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00273 
00274         private:
00275           // Methods
00276             LOG4CPLUS_PRIVATE void init();
00277 
00278           // Data
00280             bool acceptOnMatch;
00281             log4cplus::tstring stringToMatch;
00282         };
00283 
00288         class LOG4CPLUS_EXPORT FunctionFilter
00289             : public Filter
00290         {
00291         public:
00292             typedef std::function<FilterResult (const InternalLoggingEvent &)>
00293                 Function;
00294 
00295             FunctionFilter (Function);
00296 
00300             virtual FilterResult decide(const InternalLoggingEvent&) const;
00301 
00302         private:
00303             Function function;
00304         };
00305 
00306     } // end namespace spi
00307 } // end namespace log4cplus
00308 
00309 #endif /* LOG4CPLUS_SPI_FILTER_HEADER_ */