filter.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: filter.h
// Created: 5/2003
// Author: Tad E. Smith
//
//
// Copyright 1999-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_SPI_FILTER_HEADER_
#define LOG4CPLUS_SPI_FILTER_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <functional>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/loglevel.h>
namespace log4cplus {
namespace helpers
{
class Properties;
}
namespace spi {
enum FilterResult { DENY,
NEUTRAL,
ACCEPT
};
// Forward Declarations
class Filter;
class InternalLoggingEvent;
LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter* filter,
const InternalLoggingEvent& event);
typedef helpers::SharedObjectPtr<Filter> FilterPtr;
class LOG4CPLUS_EXPORT Filter
: public virtual log4cplus::helpers::SharedObject
{
public:
// ctor and dtor
Filter();
virtual ~Filter();
// Methods
void appendFilter(FilterPtr filter);
virtual FilterResult decide(const InternalLoggingEvent& event) const = 0;
// Data
FilterPtr next;
};
class LOG4CPLUS_EXPORT DenyAllFilter : public Filter {
public:
DenyAllFilter ();
DenyAllFilter (const log4cplus::helpers::Properties&);
virtual FilterResult decide(const InternalLoggingEvent& event) const;
};
class LOG4CPLUS_EXPORT LogLevelMatchFilter : public Filter {
public:
LogLevelMatchFilter();
LogLevelMatchFilter(const log4cplus::helpers::Properties& p);
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
LOG4CPLUS_PRIVATE void init();
// Data
bool acceptOnMatch;
LogLevel logLevelToMatch;
};
class LOG4CPLUS_EXPORT LogLevelRangeFilter : public Filter {
public:
// ctors
LogLevelRangeFilter();
LogLevelRangeFilter(const log4cplus::helpers::Properties& p);
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
LOG4CPLUS_PRIVATE void init();
// Data
bool acceptOnMatch;
LogLevel logLevelMin;
LogLevel logLevelMax;
};
class LOG4CPLUS_EXPORT StringMatchFilter : public Filter {
public:
// ctors
StringMatchFilter();
StringMatchFilter(const log4cplus::helpers::Properties& p);
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
LOG4CPLUS_PRIVATE void init();
// Data
bool acceptOnMatch;
log4cplus::tstring stringToMatch;
};
class LOG4CPLUS_EXPORT FunctionFilter
: public Filter
{
public:
typedef std::function<FilterResult (const InternalLoggingEvent &)>
Function;
FunctionFilter (Function);
virtual FilterResult decide(const InternalLoggingEvent&) const;
private:
Function function;
};
class LOG4CPLUS_EXPORT NDCMatchFilter : public Filter
{
public:
// ctors
NDCMatchFilter();
NDCMatchFilter(const log4cplus::helpers::Properties& p);
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
LOG4CPLUS_PRIVATE void init();
// Data
bool acceptOnMatch;
bool neutralOnEmpty;
log4cplus::tstring ndcToMatch;
};
class LOG4CPLUS_EXPORT MDCMatchFilter : public Filter
{
public:
// ctors
MDCMatchFilter();
MDCMatchFilter(const log4cplus::helpers::Properties& p);
virtual FilterResult decide(const InternalLoggingEvent& event) const;
private:
// Methods
LOG4CPLUS_PRIVATE void init();
// Data
bool acceptOnMatch;
bool neutralOnEmpty;
log4cplus::tstring mdcKeyToMatch;
log4cplus::tstring mdcValueToMatch;
};
} // end namespace spi
} // end namespace log4cplus
#endif /* LOG4CPLUS_SPI_FILTER_HEADER_ */
log4cplus::helpers::Properties
Definition property.h:43
log4cplus::helpers::SharedObjectPtr
Definition pointer.h:101
log4cplus::helpers::SharedObject
Definition pointer.h:54
log4cplus::spi::DenyAllFilter::DenyAllFilter
DenyAllFilter(const log4cplus::helpers::Properties &)
log4cplus::spi::DenyAllFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const
Always returns the DENY regardless of the InternalLoggingEvent parameter.
log4cplus::spi::DenyAllFilter::DenyAllFilter
DenyAllFilter()
log4cplus::spi::Filter
Users should extend this class to implement customized logging event filtering.
Definition filter.h:109
log4cplus::spi::Filter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const =0
If the decision is DENY, then the event will be dropped.
log4cplus::spi::Filter::~Filter
virtual ~Filter()
log4cplus::spi::Filter::appendFilter
void appendFilter(FilterPtr filter)
Appends filter to the end of this filter chain.
log4cplus::spi::Filter::next
FilterPtr next
Points to the next filter in the filter chain.
Definition filter.h:137
log4cplus::spi::Filter::Filter
Filter()
log4cplus::spi::FunctionFilter::Function
std::function< FilterResult(const InternalLoggingEvent &)> Function
Definition filter.h:293
log4cplus::spi::FunctionFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &) const
Returns result returned by function.
log4cplus::spi::FunctionFilter::FunctionFilter
FunctionFilter(Function)
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
log4cplus::spi::LogLevelMatchFilter::LogLevelMatchFilter
LogLevelMatchFilter(const log4cplus::helpers::Properties &p)
log4cplus::spi::LogLevelMatchFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const
Return the decision of this filter.
log4cplus::spi::LogLevelMatchFilter::LogLevelMatchFilter
LogLevelMatchFilter()
log4cplus::spi::LogLevelRangeFilter::LogLevelRangeFilter
LogLevelRangeFilter()
log4cplus::spi::LogLevelRangeFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const
Return the decision of this filter.
log4cplus::spi::LogLevelRangeFilter::LogLevelRangeFilter
LogLevelRangeFilter(const log4cplus::helpers::Properties &p)
log4cplus::spi::MDCMatchFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const
Returns NEUTRAL is there is no string match.
log4cplus::spi::MDCMatchFilter::MDCMatchFilter
MDCMatchFilter()
log4cplus::spi::MDCMatchFilter::MDCMatchFilter
MDCMatchFilter(const log4cplus::helpers::Properties &p)
log4cplus::spi::NDCMatchFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const
Returns NEUTRAL is there is no string match.
log4cplus::spi::NDCMatchFilter::NDCMatchFilter
NDCMatchFilter(const log4cplus::helpers::Properties &p)
log4cplus::spi::NDCMatchFilter::NDCMatchFilter
NDCMatchFilter()
log4cplus::spi::StringMatchFilter::decide
virtual FilterResult decide(const InternalLoggingEvent &event) const
Returns NEUTRAL is there is no string match.
log4cplus::spi::StringMatchFilter::StringMatchFilter
StringMatchFilter()
log4cplus::spi::StringMatchFilter::StringMatchFilter
StringMatchFilter(const log4cplus::helpers::Properties &p)
config.hxx
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition config.hxx:53
loglevel.h
This header defines the LogLevel type.
log4cplus::helpers
Definition appender.h:50
log4cplus::spi
Definition layout.h:62
log4cplus::spi::FilterResult
FilterResult
Definition filter.h:52
log4cplus::spi::ACCEPT
@ ACCEPT
The log event must be logged immediately without consulting with the remaining filters,...
Definition filter.h:59
log4cplus::spi::DENY
@ DENY
The log event must be dropped immediately without consulting with the remaining filters,...
Definition filter.h:52
log4cplus::spi::NEUTRAL
@ NEUTRAL
This filter is neutral with respect to the log event; the remaining filters, if if any,...
Definition filter.h:55
log4cplus::spi::checkFilter
LOG4CPLUS_EXPORT FilterResult checkFilter(const Filter *filter, const InternalLoggingEvent &event)
This method is used to filter an InternalLoggingEvent.
log4cplus::spi::FilterPtr
helpers::SharedObjectPtr< Filter > FilterPtr
Definition filter.h:77
log4cplus
Definition appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition loglevel.h:48
pointer.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141