CppLogging  1.0.4.0
C++ Logging Library
message_filter.h
Go to the documentation of this file.
1 
9 #ifndef CPPLOGGING_FILTERS_MESSAGE_FILTER_H
10 #define CPPLOGGING_FILTERS_MESSAGE_FILTER_H
11 
12 #include "logging/filter.h"
13 
14 #include <atomic>
15 #include <regex>
16 
17 namespace CppLogging {
18 
20 
26 class MessageFilter : public Filter
27 {
28 public:
30 
34  explicit MessageFilter(const std::regex& pattern, bool positive = true) : _positive(positive), _pattern(pattern) {}
35  MessageFilter(const MessageFilter&) = delete;
37  virtual ~MessageFilter() = default;
38 
41 
43  bool positive() const noexcept { return _positive; }
44 
46  const std::regex& pattern() const noexcept { return _pattern; }
47 
48  // Implementation of Filter
49  bool FilterRecord(Record& record) override;
50 
51 private:
52  std::atomic<bool> _positive;
53  std::regex _pattern;
54 };
55 
56 } // namespace CppLogging
57 
58 #endif // CPPLOGGING_FILTERS_MESSAGE_FILTER_H
Logging filter interface.
Definition: filter.h:29
MessageFilter & operator=(MessageFilter &&)=delete
MessageFilter & operator=(const MessageFilter &)=delete
MessageFilter(const std::regex &pattern, bool positive=true)
Initialize message filter with a given regular expression pattern.
const std::regex & pattern() const noexcept
Get the message regular expression pattern.
MessageFilter(MessageFilter &&)=delete
virtual ~MessageFilter()=default
MessageFilter(const MessageFilter &)=delete
bool positive() const noexcept
Get the positive filtration flag.
bool FilterRecord(Record &record) override
Filter the given logging record.
Logging record.
Definition: record.h:37
Logging filter interface definition.
C++ Logging project definitions.
Definition: appender.h:15