Composable log event filter with pluggable matching strategies and multi-condition support.
More...
|
| | Filter (const std::string &name="", const std::string &columnName="", const std::string &pattern="", bool caseSensitive=false, bool inverted=false, bool parameterFilter=false, const std::string ¶mKey="", int depth=0) |
| |
| | Filter (const Filter &other) |
| |
| Filter & | operator= (const Filter &other) |
| |
| | Filter (Filter &&)=default |
| |
| Filter & | operator= (Filter &&)=default |
| |
| bool | matches (const std::string &value) const |
| |
| bool | matches (const db::LogEvent &event) const |
| |
| bool | matchesParameter (const db::LogEvent &event) const |
| |
| std::vector< unsigned long > | applyToIndices (const std::vector< unsigned long > &inputIndices, const mvc::IModel &model) const |
| |
| void | compile () |
| |
| bool | searchParameterRecursive (const std::vector< std::pair< std::string, std::string > > &items, const std::string &key, int currentDepth) const |
| |
| void | addCondition (const FilterCondition &condition) |
| |
| void | removeCondition (size_t index) |
| |
| void | clearConditions () |
| |
| const std::vector< FilterCondition > & | getConditions () const |
| |
| bool | hasMultipleConditions () const |
| |
| void | setStrategy (std::unique_ptr< IFilterStrategy > strategy) |
| | Set matching strategy.
|
| |
| std::string | getStrategyName () const |
| | Get current strategy name.
|
| |
| nlohmann::json | toJson () const |
| |
Composable log event filter with pluggable matching strategies and multi-condition support.
The Filter class implements a flexible filtering system for log events, supporting:
- Single and Multiple Conditions: Conditions can be combined with AND logic
- Strategy Pattern: Pluggable matching algorithms (regex, substring, etc.)
- Complex Queries: Column matching, nested parameter search, regex patterns
- Inversion: Supports NOT logic via inverted flag
- Persistence: Filters can be serialized to JSON and restored
- Design Patterns
- Strategy Pattern: Uses IFilterStrategy for pluggable matching algorithms
- Builder Pattern: Legacy fields (name, columnName, pattern) for simple cases
- Composite Pattern: Multiple conditions combined with AND logic
- Thread Safety
- Filter instances should not be modified during concurrent matching. Strategy instances are immutable and thread-safe for concurrent reads. For thread-safe filter management, use FilterManager.
- Performance Notes
- Matching is O(k * n) where k = number of conditions, n = event fields
- Evaluation short-circuits on first false condition
- Compiled expressions are cached for efficiency
- Usage Examples
Simple single-condition filter:
error_filter.compile();
if (error_filter.matches(event)) {
}
Composable log event filter with pluggable matching strategies and multi-condition support.
Definition Filter.hpp:182
Complex multi-condition filter:
complex_filter.addCondition(
);
complex_filter.addCondition(
);
complex_filter.compile();
Represents a single matching condition within a filter structure.
Definition Filter.hpp:64
Inverted filter:
not_debug.columnName = "level";
not_debug.pattern = "DEBUG";
not_debug.isInverted = true;
not_debug.compile();
Regex pattern matching:
"IPv4 Addresses",
"ip_address",
R"(^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)"
);
regex_filter.compile();
Serialization:
nlohmann::json j = filter.toJson();
static Filter fromJson(const nlohmann::json &j)
Definition Filter.cpp:427
- See also
- FilterManager for managing multiple filters
-
FilterCondition for individual condition details
-
IFilterStrategy for custom matching strategies