ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLoggerBase.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 itkLoggerBase_h
19 #define itkLoggerBase_h
20 
21 #include "itkMultipleLogOutput.h"
22 #include "itkRealTimeClock.h"
23 
24 #ifdef DEBUG
25 #undef DEBUG // HDF5 publicly exports this define when built in debug mode
26 // That messes up the DEBUG enumeration in PriorityLevelType.
27 #endif
28 
29 namespace itk
30 {
42 class ITKCommon_EXPORT LoggerBase:public Object
43 {
44 public:
45 
46  using Self = LoggerBase;
47  using Superclass = Object;
50 
52  itkTypeMacro(LoggerBase, Object);
53 
55 
58  typedef enum {
59  MUSTFLUSH = 0,
65  NOTSET
66  } PriorityLevelType;
67 
68  itkSetStringMacro(Name);
69  itkGetStringMacro(Name);
70 
72  typedef enum {
73  REALVALUE = 0,
74  HUMANREADABLE
75  } TimeStampFormatType;
76 
86  itkSetMacro(TimeStampFormat, TimeStampFormatType);
87  itkGetConstReferenceMacro(TimeStampFormat, TimeStampFormatType);
89 
98  itkSetStringMacro(HumanReadableFormat);
99  itkGetStringMacro(HumanReadableFormat);
101 
103  virtual std::string BuildFormattedEntry(PriorityLevelType level,
104  std::string const & content);
105 
110  {
111  m_PriorityLevel = level;
112  }
113 
118  {
119  return m_PriorityLevel;
120  }
121 
123  {
124  m_LevelForFlushing = level;
125  }
126 
128  {
129  return m_LevelForFlushing;
130  }
131 
133  virtual void AddLogOutput(OutputType *output);
134 
135  virtual void Write(PriorityLevelType level, std::string const & content);
136 
138  void Debug(std::string const & message)
139  {
140  this->Write (LoggerBase::DEBUG, message);
141  }
142 
143  void Info(std::string const & message)
144  {
145  this->Write (LoggerBase::INFO, message);
146  }
147 
148  void Warning(std::string const & message)
149  {
150  this->Write (LoggerBase::WARNING, message);
151  }
152 
153  void Critical(std::string const & message)
154  {
155  this->Write (LoggerBase::CRITICAL, message);
156  }
157 
158  void Error(std::string const & message)
159  {
160  this->Write (LoggerBase::CRITICAL, message);
161  }
162 
163  void Fatal(std::string const & message)
164  {
165  this->Write (LoggerBase::FATAL, message);
166  }
167 
168  virtual void Flush();
169 
170 protected:
171 
173  LoggerBase();
174 
176  ~LoggerBase() override;
177 
179  void PrintSelf(std::ostream & os, Indent indent) const override;
180 
181 protected:
182 
184 
186 
188 
190 
192 
194 
195 private:
196 
197  std::string m_Name;
198 }; // class LoggerBase
199 } // namespace itk
200 
201 #endif // itkLoggerBase_h
void Info(std::string const &message)
Light weight base class for most itk classes.
PriorityLevelType m_LevelForFlushing
Represents an output stream.
Definition: itkLogOutput.h:39
void Debug(std::string const &message)
MultipleLogOutput::Pointer m_Output
virtual PriorityLevelType GetLevelForFlushing() const
virtual void SetPriorityLevel(PriorityLevelType level)
Used for logging information during a run.
Definition: itkLoggerBase.h:42
virtual void SetLevelForFlushing(PriorityLevelType level)
void Error(std::string const &message)
void Warning(std::string const &message)
TimeStampFormatType m_TimeStampFormat
RealTimeClock::Pointer m_Clock
void Fatal(std::string const &message)
std::string m_Name
std::string m_HumanReadableFormat
Control indentation during Print() invocation.
Definition: itkIndent.h:49
PriorityLevelType m_PriorityLevel
Base class for most ITK classes.
Definition: itkObject.h:60
virtual PriorityLevelType GetPriorityLevel() const
void Critical(std::string const &message)