ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkLoggerBase.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkLoggerBase_h
00019 #define __itkLoggerBase_h
00020 
00021 #include "itkMultipleLogOutput.h"
00022 #include "itkRealTimeClock.h"
00023 
00024 namespace itk
00025 {
00037 class ITKCommon_EXPORT LoggerBase:public Object
00038 {
00039 public:
00040 
00041   typedef LoggerBase                 Self;
00042   typedef Object                     Superclass;
00043   typedef SmartPointer< Self >       Pointer;
00044   typedef SmartPointer< const Self > ConstPointer;
00045 
00047   itkTypeMacro(LoggerBase, Object);
00048 
00049   typedef  MultipleLogOutput::OutputType OutputType;
00050 
00053   typedef enum {
00054     MUSTFLUSH = 0,
00055     FATAL,
00056     CRITICAL,
00057     WARNING,
00058     INFO,
00059     DEBUG,
00060     NOTSET
00061     } PriorityLevelType;
00062 
00063   itkSetStringMacro(Name);
00064   itkGetStringMacro(Name);
00065 
00067   typedef enum {
00068     REALVALUE = 0,
00069     HUMANREADABLE
00070     } TimeStampFormatType;
00071 
00081   itkSetMacro(TimeStampFormat, TimeStampFormatType);
00082   itkGetConstReferenceMacro(TimeStampFormat, TimeStampFormatType);
00084 
00093   itkSetStringMacro(HumanReadableFormat);
00094   itkGetStringMacro(HumanReadableFormat);
00096 
00098   virtual std::string BuildFormattedEntry(PriorityLevelType level,
00099                                           std::string const & content);
00100 
00104   virtual void SetPriorityLevel(PriorityLevelType level)
00105   {
00106     m_PriorityLevel = level;
00107   }
00108 
00112   virtual PriorityLevelType GetPriorityLevel() const
00113   {
00114     return m_PriorityLevel;
00115   }
00116 
00117   virtual void SetLevelForFlushing(PriorityLevelType level)
00118   {
00119     m_LevelForFlushing = level;
00120   }
00121 
00122   virtual PriorityLevelType GetLevelForFlushing() const
00123   {
00124     return m_LevelForFlushing;
00125   }
00126 
00128   virtual void AddLogOutput(OutputType *output);
00129 
00130   virtual void Write(PriorityLevelType level, std::string const & content);
00131 
00133   void Debug(std::string const & message)
00134   {
00135     this->Write (LoggerBase::DEBUG, message);
00136   }
00137 
00138   void Info(std::string const & message)
00139   {
00140     this->Write (LoggerBase::INFO, message);
00141   }
00142 
00143   void Warning(std::string const & message)
00144   {
00145     this->Write (LoggerBase::WARNING, message);
00146   }
00147 
00148   void Critical(std::string const & message)
00149   {
00150     this->Write (LoggerBase::CRITICAL, message);
00151   }
00152 
00153   void Error(std::string const & message)
00154   {
00155     this->Write (LoggerBase::CRITICAL, message);
00156   }
00157 
00158   void Fatal(std::string const & message)
00159   {
00160     this->Write (LoggerBase::FATAL, message);
00161   }
00162 
00163   virtual void Flush();
00164 
00165 protected:
00166 
00168   LoggerBase();
00169 
00171   virtual ~LoggerBase();
00172 
00174   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00175 
00176 protected:
00177 
00178   PriorityLevelType m_PriorityLevel;
00179 
00180   PriorityLevelType m_LevelForFlushing;
00181 
00182   MultipleLogOutput::Pointer m_Output;
00183 
00184   RealTimeClock::Pointer m_Clock;
00185 
00186   TimeStampFormatType m_TimeStampFormat;
00187 
00188   std::string m_HumanReadableFormat;
00189 private:
00190 
00191   std::string m_Name;
00192 };  // class LoggerBase
00193 } // namespace itk
00194 
00195 #endif  // __itkLoggerBase_h
00196