ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkThreadLogger.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
44  using Self = ThreadLogger;
45  using Superclass = Logger;
48 
50  itkTypeMacro(ThreadLogger, Logger);
51 
53  itkNewMacro(Self);
54 
56 
58 
59  using DelayType = unsigned int;
60 
62  typedef enum
63  {
68  FLUSH
69  }
70  OperationType;
71 
75  void SetPriorityLevel(PriorityLevelType level) override;
76 
80  PriorityLevelType GetPriorityLevel() const override;
81 
82  void SetLevelForFlushing(PriorityLevelType level) override;
83 
84  PriorityLevelType GetLevelForFlushing() const override;
85 
89  virtual void SetDelay(DelayType delay);
90 
94  virtual DelayType GetDelay() const;
95 
97  void AddLogOutput(OutputType *output) override;
98 
99  void Write(PriorityLevelType level, std::string const & content) override;
100 
101  void Flush() override;
102 
103 protected:
104 
106  ThreadLogger();
107 
109  ~ThreadLogger() override;
110 
112  void PrintSelf(std::ostream & os, Indent indent) const override;
113 
114  void ThreadFunction();
115 
116 private:
117 
118  void InternalFlush();
119 
120  using OperationContainerType = std::queue< OperationType >;
121 
122  using MessageContainerType = std::queue< std::string >;
123 
124  using LevelContainerType = std::queue< PriorityLevelType >;
125 
126  using OutputContainerType = std::queue< OutputType::Pointer >;
127 
128  std::thread m_Thread;
129 
131 
133 
135 
137 
139 
140  mutable std::mutex m_Mutex;
141 
143 
144 }; // class ThreadLogger
145 } // namespace itk
146 
147 #endif // itkThreadLogger_h
std::queue< OutputType::Pointer > OutputContainerType
std::thread m_Thread
OperationContainerType m_OperationQ
MultipleLogOutput::OutputType OutputType
Definition: itkLoggerBase.h:54
Light weight base class for most itk classes.
std::queue< PriorityLevelType > LevelContainerType
Represents an output stream.
Definition: itkLogOutput.h:39
unsigned int DelayType
Providing logging service as a separate thread.
OutputContainerType m_OutputQ
Used for logging information during a run.
Definition: itkLoggerBase.h:42
LevelContainerType m_LevelQ
std::queue< std::string > MessageContainerType
std::queue< OperationType > OperationContainerType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MessageContainerType m_MessageQ
Used for logging information during a run.
Definition: itkLogger.h:36