CppLogging  1.0.4.0
C++ Logging Library
processor.cpp
Go to the documentation of this file.
1 
9 #include "logging/processor.h"
10 
11 namespace CppLogging {
12 
14 {
15  // Flush all appenders
16  for (auto& appender : _appenders)
17  if (appender && appender->IsStarted())
18  appender->Flush();
19 
20  // Flush all sub processors
21  for (auto& processor : _processors)
22  if (processor && processor->IsStarted())
23  processor->Flush();
24 
25  // Stop the logging processor
26  if (IsStarted())
27  Stop();
28 }
29 
31 {
32  // Start logging layout
33  if (_layout && !_layout->IsStarted())
34  if (!_layout->Start())
35  return false;
36 
37  // Start logging filters
38  for (auto& filter : _filters)
39  if (filter && !filter->IsStarted())
40  if (!filter->Start())
41  return false;
42 
43  // Start logging appenders
44  for (auto& appender : _appenders)
45  if (appender && !appender->IsStarted())
46  if (!appender->Start())
47  return false;
48 
49  // Start logging processors
50  for (auto& processor : _processors)
51  if (processor)
52  if (!processor->Start())
53  return false;
54 
55  _started = true;
56 
57  return true;
58 }
59 
61 {
62  // Stop logging layout
63  if (_layout && _layout->IsStarted())
64  if (!_layout->Stop())
65  return false;
66 
67  // Stop logging filters
68  for (auto& filter : _filters)
69  if (filter && filter->IsStarted())
70  if (!filter->Stop())
71  return false;
72 
73  // Stop logging appenders
74  for (auto& appender : _appenders)
75  if (appender && appender->IsStarted())
76  if (!appender->Stop())
77  return false;
78 
79  // Stop logging processors
80  for (auto& processor : _processors)
81  if (processor)
82  if (!processor->Stop())
83  return false;
84 
85  _started = false;
86 
87  return true;
88 }
89 
91 {
92  // Filter the given logging record
93  for (auto& filter : _filters)
94  if (filter && filter->IsStarted() && !filter->FilterRecord(record))
95  return false;
96 
97  return true;
98 }
99 
101 {
102  // Check if the logging processor started
103  if (!IsStarted())
104  return true;
105 
106  // Filter the given logging record
107  if (!FilterRecord(record))
108  return true;
109 
110  // Layout the given logging record
111  if (_layout && _layout->IsStarted())
112  _layout->LayoutRecord(record);
113 
114  // Append the given logging record
115  for (auto& appender : _appenders)
116  if (appender && appender->IsStarted())
117  appender->AppendRecord(record);
118 
119  // Process the given logging record with sub processors
120  for (auto& processor : _processors)
121  if (processor && processor->IsStarted() && !processor->ProcessRecord(record))
122  return false;
123 
124  return true;
125 }
126 
128 {
129  // Check if the logging processor started
130  if (!IsStarted())
131  return;
132 
133  // Flush all appenders
134  for (auto& appender : _appenders)
135  if (appender && appender->IsStarted())
136  appender->Flush();
137 
138  // Flush all sub processors
139  for (auto& processor : _processors)
140  if (processor && processor->IsStarted())
141  processor->Flush();
142 }
143 
144 } // namespace CppLogging
std::vector< std::shared_ptr< Appender > > _appenders
Definition: processor.h:101
std::shared_ptr< Layout > _layout
Definition: processor.h:99
bool IsStarted() const noexcept override
Is the logging processor started?
Definition: processor.h:55
bool Stop() override
Stop the logging processor.
Definition: processor.cpp:60
virtual bool ProcessRecord(Record &record)
Process the given logging record through all child filters, layouts and appenders.
Definition: processor.cpp:100
bool Start() override
Start the logging processor.
Definition: processor.cpp:30
std::atomic< bool > _started
Definition: processor.h:98
std::vector< std::shared_ptr< Filter > > _filters
Definition: processor.h:100
std::vector< std::shared_ptr< Processor > > _processors
Definition: processor.h:102
virtual void Flush()
Flush the current logging processor.
Definition: processor.cpp:127
virtual bool FilterRecord(Record &record)
Filter the given logging record.
Definition: processor.cpp:90
Logging record.
Definition: record.h:37
C++ Logging project definitions.
Definition: appender.h:15
Logging processor interface definition.