CppLogging  1.0.4.0
C++ Logging Library
level_filter.h
Go to the documentation of this file.
1 
9 #ifndef CPPLOGGING_FILTERS_LEVEL_FILTER_H
10 #define CPPLOGGING_FILTERS_LEVEL_FILTER_H
11 
12 #include "logging/filter.h"
13 
14 #include <atomic>
15 
16 namespace CppLogging {
17 
19 
25 class LevelFilter : public Filter
26 {
27 public:
29 
33  explicit LevelFilter(Level level, bool positive = true) { Update(level, positive); }
35 
40  explicit LevelFilter(Level from, Level to, bool positive = true) { Update(from, to, positive); }
41  LevelFilter(const LevelFilter&) = delete;
42  LevelFilter(LevelFilter&&) = delete;
43  virtual ~LevelFilter() = default;
44 
45  LevelFilter& operator=(const LevelFilter&) = delete;
47 
49  bool positive() const noexcept { return _positive; }
50 
52  Level from() const noexcept { return _from; }
54  Level to() const noexcept { return _to; }
55 
57 
61  void Update(Level level, bool positive = true);
63 
68  void Update(Level from, Level to, bool positive = true);
69 
70  // Implementation of Filter
71  bool FilterRecord(Record& record) override;
72 
73 private:
74  std::atomic<bool> _positive;
75  std::atomic<Level> _from;
76  std::atomic<Level> _to;
77 };
78 
79 } // namespace CppLogging
80 
81 #endif // CPPLOGGING_FILTERS_LEVEL_FILTER_H
Logging filter interface.
Definition: filter.h:29
LevelFilter & operator=(const LevelFilter &)=delete
Level from() const noexcept
Get Level from value.
Definition: level_filter.h:52
LevelFilter(Level from, Level to, bool positive=true)
Initialize level filter with a given level range.
Definition: level_filter.h:40
Level to() const noexcept
Get Level to value.
Definition: level_filter.h:54
LevelFilter(const LevelFilter &)=delete
virtual ~LevelFilter()=default
bool positive() const noexcept
Get the positive filtration flag.
Definition: level_filter.h:49
LevelFilter & operator=(LevelFilter &&)=delete
bool FilterRecord(Record &record) override
Filter the given logging record.
void Update(Level level, bool positive=true)
Update level filter with a given level value.
LevelFilter(Level level, bool positive=true)
Initialize level filter with a given level value.
Definition: level_filter.h:33
LevelFilter(LevelFilter &&)=delete
Logging record.
Definition: record.h:37
Logging filter interface definition.
C++ Logging project definitions.
Definition: appender.h:15
Level
Logging level.
Definition: level.h:18