CppLogging  1.0.4.0
C++ Logging Library
trigger.h
Go to the documentation of this file.
1 
9 #ifndef CPPLOGGING_TRIGGER_H
10 #define CPPLOGGING_TRIGGER_H
11 
12 #include "logging/filter.h"
13 
14 #include <atomic>
15 
16 namespace CppLogging {
17 
19 
24 class Trigger : public Filter
25 {
26 public:
28 
31  explicit Trigger(bool state = true) : _state(state) {}
32  Trigger(const Trigger&) = delete;
33  Trigger(Trigger&&) = delete;
34  virtual ~Trigger() = default;
35 
36  Trigger& operator=(const Trigger&) = delete;
37  Trigger& operator=(Trigger&&) = delete;
38 
40  bool IsEnabled() noexcept { return _state; }
41 
43  void Enable() noexcept { _state = true; }
45  void Disable() noexcept { _state = false; }
47  void Toggle() noexcept { _state = !_state; }
48 
49  // Implementation of Filter
50  bool FilterRecord(Record& record) override
51  { return _state; }
52 
53 private:
54  std::atomic<bool> _state;
55 };
56 
57 } // namespace CppLogging
58 
59 #endif // CPPLOGGING_TRIGGER_H
Logging filter interface.
Definition: filter.h:29
Logging record.
Definition: record.h:37
Logging trigger.
Definition: trigger.h:25
Trigger & operator=(Trigger &&)=delete
void Enable() noexcept
Enable logging.
Definition: trigger.h:43
bool IsEnabled() noexcept
Is logging enabled?
Definition: trigger.h:40
void Toggle() noexcept
Toggle logging.
Definition: trigger.h:47
Trigger(const Trigger &)=delete
virtual ~Trigger()=default
Trigger & operator=(const Trigger &)=delete
Trigger(Trigger &&)=delete
Trigger(bool state=true)
Initialize trigger with an initial logging state (enabled or disabled)
Definition: trigger.h:31
bool FilterRecord(Record &record) override
Filter the given logging record.
Definition: trigger.h:50
void Disable() noexcept
Disable logging.
Definition: trigger.h:45
Logging filter interface definition.
C++ Logging project definitions.
Definition: appender.h:15