ITK  6.0.0
Insight Toolkit
itkThreadLogger.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkThreadLogger_h
19#define itkThreadLogger_h
20
21#include "itkLogger.h"
22#include <mutex>
23#include <atomic>
24
25#include <string>
26#include <queue>
27#include <thread>
28
29namespace itk
30{
41class ITKCommon_EXPORT ThreadLogger : public Logger
42{
43public:
48
50 itkOverrideGetNameOfClassMacro(ThreadLogger);
51
53 itkNewMacro(Self);
54
56
58
59 using DelayType = unsigned int;
60
62 typedef enum
63 {
68 FLUSH
69 } OperationType;
70
74 void
76
81 GetPriorityLevel() const override;
82
83 void
85
87 GetLevelForFlushing() const override;
88
92 virtual void
94
98 virtual DelayType
99 GetDelay() const;
100
102 void
103 AddLogOutput(OutputType * output) override;
104
105 void
106 Write(PriorityLevelEnum level, std::string const & content) override;
107
108 void
109 Flush() override;
110
111protected:
114
116 ~ThreadLogger() override;
117
119 void
120 PrintSelf(std::ostream & os, Indent indent) const override;
121
122 void
124
125private:
126 void
128
129 std::thread m_Thread{};
130
131 std::atomic<bool> m_TerminationRequested{};
132
133 std::queue<OperationType> m_OperationQ{};
134
135 std::queue<std::string> m_MessageQ{};
136
137 std::queue<PriorityLevelEnum> m_LevelQ{};
138
139 std::queue<OutputType::Pointer> m_OutputQ{};
140
141 mutable std::mutex m_Mutex{};
142
143 DelayType m_Delay{};
144
145}; // class ThreadLogger
146} // namespace itk
147
148#endif // itkThreadLogger_h
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Represents an output stream.
Definition: itkLogOutput.h:40
Used for logging information during a run.
Definition: itkLoggerBase.h:82
LoggerBaseEnums::PriorityLevel PriorityLevelEnum
Definition: itkLoggerBase.h:94
MultipleLogOutput::OutputType OutputType
Definition: itkLoggerBase.h:92
Used for logging information during a run.
Definition: itkLogger.h:37
Providing logging service as a separate thread.
~ThreadLogger() override
void SetPriorityLevel(PriorityLevelEnum level) override
void Flush() override
void SetLevelForFlushing(PriorityLevelEnum level) override
virtual DelayType GetDelay() const
unsigned int DelayType
void AddLogOutput(OutputType *output) override
PriorityLevelEnum GetPriorityLevel() const override
Logger::PriorityLevelEnum PriorityLevelEnum
void PrintSelf(std::ostream &os, Indent indent) const override
void Write(PriorityLevelEnum level, std::string const &content) override
PriorityLevelEnum GetLevelForFlushing() const override
virtual void SetDelay(DelayType delay)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....