log4cplus  1.1.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-2010 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 <log4cplus/helpers/pointer.h>
00035 #include <log4cplus/loglevel.h>
00036 
00037 
00038 namespace log4cplus {
00039 
00040     namespace helpers
00041     {
00042 
00043         class Properties;
00044 
00045     }
00046 
00047     namespace spi {
00048 
00049 
00050         enum FilterResult { DENY, 
00053                             NEUTRAL, 
00057                             ACCEPT 
00060                           };
00061 
00062         // Forward Declarations
00063         class Filter;
00064         class InternalLoggingEvent;
00065 
00066 
00072         LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter* filter, 
00073                                                   const InternalLoggingEvent& event);
00074 
00075         typedef helpers::SharedObjectPtr<Filter> FilterPtr;
00076 
00077 
00105         class LOG4CPLUS_EXPORT Filter 
00106             : public virtual log4cplus::helpers::SharedObject 
00107         {
00108         public:
00109           // ctor and dtor
00110             Filter();
00111             virtual ~Filter();
00112 
00113           // Methods
00117             void appendFilter(FilterPtr filter);
00118 
00129             virtual FilterResult decide(const InternalLoggingEvent& event) const = 0;
00130 
00131           // Data
00135             FilterPtr next;
00136         };
00137   
00138 
00139 
00148         class LOG4CPLUS_EXPORT DenyAllFilter : public Filter {
00149         public:
00150             DenyAllFilter ();
00151             DenyAllFilter (const log4cplus::helpers::Properties&);
00152 
00157             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00158         };
00159 
00160 
00172         class LOG4CPLUS_EXPORT LogLevelMatchFilter : public Filter {
00173         public:
00174             LogLevelMatchFilter();
00175             LogLevelMatchFilter(const log4cplus::helpers::Properties& p);
00176 
00187             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00188 
00189         private:
00190           // Methods
00191             LOG4CPLUS_PRIVATE void init();
00192 
00193           // Data
00195             bool acceptOnMatch;
00196             LogLevel logLevelToMatch;
00197         };
00198 
00199 
00200 
00226         class LOG4CPLUS_EXPORT LogLevelRangeFilter : public Filter {
00227         public:
00228           // ctors
00229             LogLevelRangeFilter();
00230             LogLevelRangeFilter(const log4cplus::helpers::Properties& p);
00231 
00235             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00236 
00237         private:
00238           // Methods
00239             LOG4CPLUS_PRIVATE void init();
00240 
00241           // Data
00243             bool acceptOnMatch;
00244             LogLevel logLevelMin;
00245             LogLevel logLevelMax;
00246         };
00247 
00248 
00249 
00261         class LOG4CPLUS_EXPORT StringMatchFilter : public Filter {
00262         public:
00263           // ctors
00264             StringMatchFilter();
00265             StringMatchFilter(const log4cplus::helpers::Properties& p);
00266 
00270             virtual FilterResult decide(const InternalLoggingEvent& event) const;
00271 
00272         private:
00273           // Methods
00274             LOG4CPLUS_PRIVATE void init();
00275 
00276           // Data
00278             bool acceptOnMatch;
00279             log4cplus::tstring stringToMatch;
00280         };
00281 
00282     } // end namespace spi
00283 } // end namespace log4cplus
00284 
00285 #endif /* LOG4CPLUS_SPI_FILTER_HEADER_ */
00286 
00287