ITK  6.0.0
Insight Toolkit
itkLoggerBase.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 itkLoggerBase_h
19#define itkLoggerBase_h
20
22#include "itkRealTimeClock.h"
23#include "ITKCommonExport.h"
24#ifdef DEBUG
25# undef DEBUG // HDF5 publicly exports this define when built in debug mode
26// That messes up the DEBUG enumeration in PriorityLevelEnum.
27#endif
28
29namespace itk
30{
31/*** \class LoggerBaseEnums
32 * \brief Contains all enum classes used by LoggerBase class.
33 * \ingroup ITKCommon
34 */
36{
37public:
43 enum class PriorityLevel : uint8_t
44 {
45 MUSTFLUSH = 0,
46 FATAL,
47 CRITICAL,
48 WARNING,
49 INFO,
50 DEBUG,
51 NOTSET
52 };
53
57 enum class TimeStampFormat : uint8_t
58 {
59 REALVALUE = 0,
60 HUMANREADABLE = 1
61 };
62};
63
64// Define how to print enumeration
65extern ITKCommon_EXPORT std::ostream &
66 operator<<(std::ostream & out, const LoggerBaseEnums::PriorityLevel value);
67extern ITKCommon_EXPORT std::ostream &
68 operator<<(std::ostream & out, const LoggerBaseEnums::TimeStampFormat value);
69
81class ITKCommon_EXPORT LoggerBase : public Object
82{
83public:
88
90 itkOverrideGetNameOfClassMacro(LoggerBase);
91
93
95#if !defined(ITK_LEGACY_REMOVE)
96 // We need to expose the enum values at the class level
97 // for backwards compatibility
98 static constexpr PriorityLevelEnum MUSTFLUSH = PriorityLevelEnum::MUSTFLUSH;
99 static constexpr PriorityLevelEnum FATAL = PriorityLevelEnum::FATAL;
100 static constexpr PriorityLevelEnum CRITICAL = PriorityLevelEnum::CRITICAL;
101 static constexpr PriorityLevelEnum WARNING = PriorityLevelEnum::WARNING;
102 static constexpr PriorityLevelEnum INFO = PriorityLevelEnum::INFO;
103 static constexpr PriorityLevelEnum DEBUG = PriorityLevelEnum::DEBUG;
104 static constexpr PriorityLevelEnum NOTSET = PriorityLevelEnum::NOTSET;
105#endif
106
107 itkSetStringMacro(Name);
108 itkGetStringMacro(Name);
109
111#if !defined(ITK_LEGACY_REMOVE)
112 // We need to expose the enum values at the class level
113 // for backwards compatibility
114 static constexpr TimeStampFormatEnum REALVALUE = TimeStampFormatEnum::REALVALUE;
115 static constexpr TimeStampFormatEnum HUMANREADABLE = TimeStampFormatEnum::HUMANREADABLE;
116#endif
117
127 itkSetEnumMacro(TimeStampFormat, TimeStampFormatEnum);
128 itkGetConstReferenceMacro(TimeStampFormat, TimeStampFormatEnum);
139 itkSetStringMacro(HumanReadableFormat);
140 itkGetStringMacro(HumanReadableFormat);
144 virtual std::string
145 BuildFormattedEntry(PriorityLevelEnum level, std::string const & content);
146
150 virtual void
152 {
153 m_PriorityLevel = level;
154 }
155
159 virtual PriorityLevelEnum
161 {
162 return m_PriorityLevel;
163 }
164
165 virtual void
167 {
168 m_LevelForFlushing = level;
169 }
170
171 virtual PriorityLevelEnum
173 {
174 return m_LevelForFlushing;
175 }
176
178 virtual void
180
181 virtual void
182 Write(PriorityLevelEnum level, std::string const & content);
183
185 void
186 Debug(std::string const & message)
187 {
188 this->Write(LoggerBase::PriorityLevelEnum::DEBUG, message);
189 }
190
191 void
192 Info(std::string const & message)
193 {
194 this->Write(LoggerBase::PriorityLevelEnum::INFO, message);
195 }
196
197 void
198 Warning(std::string const & message)
199 {
200 this->Write(LoggerBase::PriorityLevelEnum::WARNING, message);
201 }
202
203 void
204 Critical(std::string const & message)
205 {
206 this->Write(LoggerBase::PriorityLevelEnum::CRITICAL, message);
207 }
208
209 void
210 Error(std::string const & message)
211 {
212 this->Write(LoggerBase::PriorityLevelEnum::CRITICAL, message);
213 }
214
215 void
216 Fatal(std::string const & message)
217 {
218 this->Write(LoggerBase::PriorityLevelEnum::FATAL, message);
219 }
220
221 virtual void
223
224protected:
225 virtual void
227
230
232 ~LoggerBase() override;
233
235 void
236 PrintSelf(std::ostream & os, Indent indent) const override;
237
238protected:
239 PriorityLevelEnum m_PriorityLevel{};
240
241 PriorityLevelEnum m_LevelForFlushing{};
242
244
246
247 TimeStampFormatEnum m_TimeStampFormat{};
248
249 std::string m_HumanReadableFormat{};
250
251private:
252 std::string m_Name{};
253}; // class LoggerBase
254} // namespace itk
255
256#endif // itkLoggerBase_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
virtual void SetLevelForFlushing(PriorityLevelEnum level)
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void PrivateFlush()
virtual PriorityLevelEnum GetPriorityLevel() const
virtual PriorityLevelEnum GetLevelForFlushing() const
virtual void Write(PriorityLevelEnum level, std::string const &content)
~LoggerBase() override
void Error(std::string const &message)
virtual void Flush()
virtual void SetPriorityLevel(PriorityLevelEnum level)
void Warning(std::string const &message)
void Fatal(std::string const &message)
virtual std::string BuildFormattedEntry(PriorityLevelEnum level, std::string const &content)
virtual void AddLogOutput(OutputType *output)
void Debug(std::string const &message)
void Info(std::string const &message)
void Critical(std::string const &message)
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)