Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::regex_filter Class Reference

Filter logs by regex pattern. More...

#include <log_filter.h>

Inheritance diagram for kcenon::logger::regex_filter:
Inheritance graph
Collaboration diagram for kcenon::logger::regex_filter:
Collaboration graph

Public Member Functions

 regex_filter (const std::string &pattern, bool include=true)
 
bool should_log (log_level level, const std::string &message, const std::string &file, int line, const std::string &function) const override
 Check if a log entry should be processed (legacy API)
 
std::string get_name () const override
 Get the name of this filter.
 
- Public Member Functions inherited from kcenon::logger::log_filter
virtual ~log_filter ()=default
 
virtual bool should_log (const log_entry &entry) const override
 Check if a log entry should be processed (new interface)
 
- Public Member Functions inherited from kcenon::logger::log_filter_interface
virtual ~log_filter_interface ()=default
 

Private Attributes

std::regex pattern_
 
bool include_
 

Detailed Description

Filter logs by regex pattern.

Definition at line 105 of file log_filter.h.

Constructor & Destructor Documentation

◆ regex_filter()

kcenon::logger::regex_filter::regex_filter ( const std::string & pattern,
bool include = true )
inlineexplicit

Definition at line 107 of file log_filter.h.

108 : pattern_(pattern), include_(include) {}

Member Function Documentation

◆ get_name()

std::string kcenon::logger::regex_filter::get_name ( ) const
inlineoverridevirtual

Get the name of this filter.

Returns
Filter name for identification

Reimplemented from kcenon::logger::log_filter.

Definition at line 123 of file log_filter.h.

123 {
124 return "regex_filter";
125 }

◆ should_log()

bool kcenon::logger::regex_filter::should_log ( log_level level,
const std::string & message,
const std::string & file,
int line,
const std::string & function ) const
inlineoverridevirtual

Check if a log entry should be processed (legacy API)

Parameters
levelLog level
messageLog message
fileSource file
lineSource line
functionFunction name
Returns
true if the log should be processed

Implements kcenon::logger::log_filter.

Definition at line 110 of file log_filter.h.

114 {
115 (void)level;
116 (void)file;
117 (void)line;
118 (void)function;
119 bool matches = std::regex_search(message, pattern_);
120 return include_ ? matches : !matches;
121 }

References include_, and pattern_.

Member Data Documentation

◆ include_

bool kcenon::logger::regex_filter::include_
private

Definition at line 129 of file log_filter.h.

Referenced by should_log().

◆ pattern_

std::regex kcenon::logger::regex_filter::pattern_
private

Definition at line 128 of file log_filter.h.

Referenced by should_log().


The documentation for this class was generated from the following file: