14#include <kcenon/common/interfaces/logger_interface.h>
22using log_level = common::interfaces::log_level;
41 return "level_filter";
62 return "exact_level_filter";
75 regex_filter(
const std::string& pattern,
bool include_matches =
true)
84 return "regex_filter";
96 std::vector<std::unique_ptr<log_filter_interface>>
filters_;
102 void add_filter(std::unique_ptr<log_filter_interface> filter) {
103 filters_.push_back(std::move(filter));
110 for (
const auto& filter :
filters_) {
111 if (!filter->should_log(entry)) {
117 for (
const auto& filter :
filters_) {
118 if (filter->should_log(entry)) {
146 return "function_filter";
171 bool has_field = entry.
fields.has_value() &&
177 return "field_exists_filter";
204 if (!entry.
fields.has_value()) {
209 if (it == entry.
fields->end()) {
214 return negate_ ? !matches : matches;
218 return "field_value_filter";
248 bool inclusive_min =
true,
249 bool inclusive_max =
true)
257 if (!entry.
fields.has_value()) {
262 if (it == entry.
fields->end()) {
268 if (std::holds_alternative<int64_t>(it->second)) {
269 value =
static_cast<double>(std::get<int64_t>(it->second));
270 }
else if (std::holds_alternative<double>(it->second)) {
271 value = std::get<double>(it->second);
279 return above_min && below_max;
283 return "field_range_filter";
307 const std::string& pattern,
308 bool include_matches =
true)
314 if (!entry.
fields.has_value()) {
319 if (it == entry.
fields->end()) {
324 if (!std::holds_alternative<std::string>(it->second)) {
328 const auto& str_value = std::get<std::string>(it->second);
329 bool matches = std::regex_search(str_value,
pattern_);
334 return "field_regex_filter";
363 std::string cat = entry.
category->to_string();
369 return "category_filter";
Filter based on category field.
std::string get_name() const override
Get the name of this filter.
std::vector< std::string > categories_
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
category_filter(std::vector< std::string > categories, bool include=true)
Constructor.
Composite filter with AND/OR logic.
void add_filter(std::unique_ptr< log_filter_interface > filter)
std::vector< std::unique_ptr< log_filter_interface > > filters_
std::string get_name() const override
Get the name of this filter.
composite_filter(logic_type logic)
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
Exact level filter (matches only the specified level)
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
exact_level_filter(log_level level)
std::string get_name() const override
Get the name of this filter.
Filter based on structured field presence.
std::string get_name() const override
Get the name of this filter.
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
field_exists_filter(const std::string &field_name, bool require_exists=true)
Constructor.
Filter based on structured field value range (for numeric types)
std::string get_name() const override
Get the name of this filter.
field_range_filter(const std::string &field_name, double min_value, double max_value, bool inclusive_min=true, bool inclusive_max=true)
Constructor.
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
Filter based on string field pattern matching.
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
field_regex_filter(const std::string &field_name, const std::string &pattern, bool include_matches=true)
Constructor.
std::string get_name() const override
Get the name of this filter.
Filter based on structured field value.
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
log_value expected_value_
std::string get_name() const override
Get the name of this filter.
field_value_filter(const std::string &field_name, log_value expected_value, bool negate=false)
Constructor.
function_filter(decltype(predicate_) predicate)
std::string get_name() const override
Get the name of this filter.
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
std::function< bool(const log_entry &)> predicate_
Level-based log filter (minimum level threshold)
level_filter(log_level min_level)
std::string get_name() const override
Get the name of this filter.
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
regex_filter(const std::string &pattern, bool include_matches=true)
bool should_log(const log_entry &entry) const override
Check if a log entry should be processed.
std::string get_name() const override
Get the name of this filter.
Interface for log filters.
std::string to_string() const
Convert to std::string.
Data structures for representing log entries and source locations kcenon.
Interface for log filters used by filtered_logger.
std::variant< std::string, int64_t, double, bool > log_value
Value type for structured logging fields.
Represents a single log entry with all associated metadata.
std::optional< log_fields > fields
Optional structured fields for key-value logging.
log_level level
Severity level of the log message.
std::optional< small_string_128 > category
Optional category for log filtering and routing.
small_string_256 message
The actual log message.