ITK  5.2.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  * http://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 
24 #include <string>
25 #include <queue>
26 #include <thread>
27 
28 namespace itk
29 {
40 class ITKCommon_EXPORT ThreadLogger : public Logger
41 {
42 public:
43  using Self = ThreadLogger;
44  using Superclass = Logger;
47 
49  itkTypeMacro(ThreadLogger, Logger);
50 
52  itkNewMacro(Self);
53 
55 
57 
58  using DelayType = unsigned int;
59 
61  typedef enum
62  {
67  FLUSH
68  } OperationType;
69 
73  void
74  SetPriorityLevel(PriorityLevelEnum level) override;
75 
79  PriorityLevelEnum
80  GetPriorityLevel() const override;
81 
82  void
83  SetLevelForFlushing(PriorityLevelEnum level) override;
84 
85  PriorityLevelEnum
86  GetLevelForFlushing() const override;
87 
91  virtual void
92  SetDelay(DelayType delay);
93 
97  virtual DelayType
98  GetDelay() const;
99 
101  void
102  AddLogOutput(OutputType * output) override;
103 
104  void
105  Write(PriorityLevelEnum level, std::string const & content) override;
106 
107  void
108  Flush() override;
109 
110 protected:
112  ThreadLogger();
113 
115  ~ThreadLogger() override;
116 
118  void
119  PrintSelf(std::ostream & os, Indent indent) const override;
120 
121  void
122  ThreadFunction();
123 
124 private:
125  void
126  InternalFlush();
127 
128  using OperationContainerType = std::queue<OperationType>;
129 
130  using MessageContainerType = std::queue<std::string>;
131 
132  using LevelContainerType = std::queue<PriorityLevelEnum>;
133 
134  using OutputContainerType = std::queue<OutputType::Pointer>;
135 
136  std::thread m_Thread;
137 
139 
141 
143 
145 
147 
148  mutable std::mutex m_Mutex;
149 
151 
152 }; // class ThreadLogger
153 } // namespace itk
154 
155 #endif // itkThreadLogger_h
itk::LoggerBase::PriorityLevelEnum
LoggerBaseEnums::PriorityLevel PriorityLevelEnum
Definition: itkLoggerBase.h:94
itk::ThreadLogger::SET_LEVEL_FOR_FLUSHING
Definition: itkThreadLogger.h:64
itk::ThreadLogger::m_MessageQ
MessageContainerType m_MessageQ
Definition: itkThreadLogger.h:142
itk::ThreadLogger::ADD_LOG_OUTPUT
Definition: itkThreadLogger.h:65
itk::Logger
Used for logging information during a run.
Definition: itkLogger.h:36
itk::LoggerBaseEnums::PriorityLevel
PriorityLevel
Definition: itkLoggerBase.h:43
itk::LoggerBase::OutputType
MultipleLogOutput::OutputType OutputType
Definition: itkLoggerBase.h:92
itk::ThreadLogger::m_TerminationRequested
bool m_TerminationRequested
Definition: itkThreadLogger.h:138
itk::ThreadLogger::SET_PRIORITY_LEVEL
Definition: itkThreadLogger.h:63
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ThreadLogger::m_LevelQ
LevelContainerType m_LevelQ
Definition: itkThreadLogger.h:144
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::LogOutput
Represents an output stream.
Definition: itkLogOutput.h:39
itk::ThreadLogger::m_Delay
DelayType m_Delay
Definition: itkThreadLogger.h:150
itk::ThreadLogger::m_Thread
std::thread m_Thread
Definition: itkThreadLogger.h:136
itk::ThreadLogger::LevelContainerType
std::queue< PriorityLevelEnum > LevelContainerType
Definition: itkThreadLogger.h:132
itk::ThreadLogger::m_OperationQ
OperationContainerType m_OperationQ
Definition: itkThreadLogger.h:140
itk::ThreadLogger::OperationContainerType
std::queue< OperationType > OperationContainerType
Definition: itkThreadLogger.h:128
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ThreadLogger::m_OutputQ
OutputContainerType m_OutputQ
Definition: itkThreadLogger.h:146
itk::ThreadLogger
Providing logging service as a separate thread.
Definition: itkThreadLogger.h:40
itk::ThreadLogger::OutputContainerType
std::queue< OutputType::Pointer > OutputContainerType
Definition: itkThreadLogger.h:134
itk::ThreadLogger::m_Mutex
std::mutex m_Mutex
Definition: itkThreadLogger.h:148
itk::LoggerBase
Used for logging information during a run.
Definition: itkLoggerBase.h:81
itk::ThreadLogger::MessageContainerType
std::queue< std::string > MessageContainerType
Definition: itkThreadLogger.h:130
itk::ThreadLogger::DelayType
unsigned int DelayType
Definition: itkThreadLogger.h:58
itkLogger.h
itk::ThreadLogger::WRITE
Definition: itkThreadLogger.h:66