18#include <unordered_map>
38 using creator_fn = std::function<std::unique_ptr<log_filter_interface>()>;
52 return std::make_unique<filters::level_filter>(min_level);
62 const std::string& pattern,
63 bool include_matches =
true
65 return std::make_unique<filters::regex_filter>(pattern, include_matches);
74 std::function<
bool(
const log_entry&)> predicate
76 return std::make_unique<filters::function_filter>(std::move(predicate));
84 return std::make_unique<filters::composite_filter>(
94 return std::make_unique<filters::composite_filter>(
136 const std::string& component
147 "password|secret|token|api.?key|credential|auth|bearer",
197 std::unique_ptr<log_filter_interface>
build() {
207 composite->add_filter(std::move(filter));
213 std::vector<std::unique_ptr<log_filter_interface>>
filters_;
234 registry()[name] = std::move(creator);
242 static std::unique_ptr<log_filter_interface>
create(
const std::string& name) {
260 static std::unordered_map<std::string, creator_fn>&
registry() {
261 static std::unordered_map<std::string, creator_fn> instance;
Filter builder for complex filter construction.
builder & exclude_pattern(const std::string &pattern)
Exclude messages matching pattern.
std::unique_ptr< log_filter_interface > build()
Build the composite filter.
builder & with_min_level(log_level level)
Set minimum log level.
builder & include_pattern(const std::string &pattern)
Include messages matching pattern.
builder & with_predicate(std::function< bool(const log_entry &)> pred)
Add custom filter function.
std::vector< std::unique_ptr< log_filter_interface > > filters_
Factory for creating log filter instances.
static std::unique_ptr< log_filter_interface > create_function(std::function< bool(const log_entry &)> predicate)
Create a function-based filter.
static std::unique_ptr< log_filter_interface > create_component_filter(const std::string &component)
Create a debug filter for specific component.
static void register_type(const std::string &name, creator_fn creator)
Register a custom filter type.
static std::unique_ptr< log_filter_interface > create_production()
Create a production filter.
static std::unique_ptr< filters::composite_filter > create_composite_and()
Create a composite filter with AND logic.
static std::unique_ptr< log_filter_interface > create_sensitive_filter()
Create a sensitive data filter.
static std::unique_ptr< log_filter_interface > create_development()
Create a development filter.
static std::unique_ptr< filters::composite_filter > create_composite_or()
Create a composite filter with OR logic.
std::function< std::unique_ptr< log_filter_interface >()> creator_fn
static std::unique_ptr< log_filter_interface > create(const std::string &name)
Create a filter by registered name.
static std::unique_ptr< log_filter_interface > create_errors_only()
Create an error-only filter.
static std::unique_ptr< log_filter_interface > create_level(log_level min_level)
Create a level filter.
static std::unordered_map< std::string, creator_fn > & registry()
static bool has_type(const std::string &name)
Check if a filter type is registered.
static builder create_builder()
Start building a filter.
static std::unique_ptr< log_filter_interface > create_regex(const std::string &pattern, bool include_matches=true)
Create a regex filter.
Log filtering functionality.
Data structures for representing log entries and source locations kcenon.
Interface for log filters used by filtered_logger.
Represents a single log entry with all associated metadata.