Skip to content

Commit

Permalink
ENH: Classes for supporting Logging. These classes will facilitate de…
Browse files Browse the repository at this point in the history
…bugging

     during development and will provide services for run-time tracing of
     program activities.
  • Loading branch information
Luis Ibanez committed May 26, 2005
1 parent 66c73a2 commit e3e00ad
Show file tree
Hide file tree
Showing 19 changed files with 1,949 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Code/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SET(ITKCommon_SRCS
itkChainCodePath2D.cxx
itkCommand.h itkCommand.cxx
itkConditionVariable.cxx
itkConsoleLogOutput.cxx
itkDataObject.cxx
itkDecisionRuleBase.cxx
itkDirectory.cxx
Expand All @@ -14,6 +15,7 @@ SET(ITKCommon_SRCS
itkExceptionObject.cxx
itkFastMutexLock.cxx
itkFileOutputWindow.cxx
itkFileLogOutput.cxx
itkGaussianKernelFunction.cxx
itkHexahedronCellTopology.cxx
itkIndent.cxx
Expand All @@ -23,12 +25,16 @@ SET(ITKCommon_SRCS
itkKernelFunction.cxx
itkLightObject.cxx
itkLightProcessObject.cxx
itkLogger.cxx
itkLoggerManager.cxx
itkLoggerOutput.cxx
itkMaximumDecisionRule.cxx
itkMaximumRatioDecisionRule.cxx
itkMeshRegion.cxx
itkMinimumDecisionRule.cxx
itkMultiThreader.cxx
itkMutexLock.cxx
itkMultipleLogOutput.cxx
itkNumericTraits.cxx
itkNumericTraitsRGBPixel.cxx
itkNumericTraitsVectorPixel.cxx
Expand All @@ -51,8 +57,10 @@ SET(ITKCommon_SRCS
itkSimpleFastMutexLock.cxx
itkSimpleFilterWatcher.cxx
itkSimplexMeshGeometry.cxx
itkStdStreamLogOutput.cxx
itkTextOutput.cxx
itkTetrahedronCellTopology.cxx
itkThreadLogger.cxx
itkTimeProbe.cxx
itkTimeProbesCollectorBase.cxx
itkTimeStamp.cxx
Expand Down
81 changes: 81 additions & 0 deletions Code/Common/itkConsoleLogOutput.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkConsoleLogOutput.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

#include<iostream>
#include"itkConsoleLogOutput.h"


namespace itk
{

SimpleFastMutexLock ConsoleLogOutput::m_Mutex;


ConsoleLogOutput::ConsoleLogOutput()
{
m_Mutex.Lock();
std::cout.precision(15);
m_Mutex.Unlock();
}


ConsoleLogOutput::~ConsoleLogOutput()
{
m_Mutex.Lock();
std::cout.flush();
m_Mutex.Unlock();
}


/** flush a buffer */
void ConsoleLogOutput::Flush()
{
ConsoleLogOutput::m_Mutex.Lock();
std::cout.flush();
ConsoleLogOutput::m_Mutex.Unlock();
}


/** Write to a buffer */
void ConsoleLogOutput::Write(double timestamp)
{
ConsoleLogOutput::m_Mutex.Lock();
std::cout << timestamp;
ConsoleLogOutput::m_Mutex.Unlock();
}


/** Write to a buffer */
void ConsoleLogOutput::Write(std::string const &content)
{
ConsoleLogOutput::m_Mutex.Lock();
std::cout << content;
ConsoleLogOutput::m_Mutex.Unlock();
}


/** Write to a buffer */
void ConsoleLogOutput::Write(std::string const &content, double timestamp)
{
ConsoleLogOutput::m_Mutex.Lock();
std::cout << timestamp << " : " << content;
ConsoleLogOutput::m_Mutex.Unlock();
}


}

84 changes: 84 additions & 0 deletions Code/Common/itkConsoleLogOutput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkConsoleLogOutput.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

#ifndef __itk_ConsoleLogOutput_h_
#define __itk_ConsoleLogOutput_h_

#include <string>

#include "itkMacro.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkSimpleFastMutexLock.h"
#include "itkLogOutput.h"


namespace itk
{

/** \class ConsoleLogOutput
* \brief Class ConsoleLogOutput represents a standard output stream.
* This class provides thread safety for the standard output stream.
*
* \author Hee-Su Kim, Compute Science Dept. Kyungpook National University,
* ISIS Center, Georgetown University.
*
*
* \ingroup OSSystemObjects LoggingObjects
*/

class ConsoleLogOutput : public LogOutput
{

public:

typedef ConsoleLogOutput Self;
typedef LogOutput Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;

itkTypeMacro(ConsoleLogOutput, LogOutput);

itkNewMacro(ConsoleLogOutput);

/** flush a buffer */
virtual void Flush();

/** Write to a buffer */
virtual void Write(double timestamp);

/** Write to a buffer */
virtual void Write(std::string const &content);

/** Write to a buffer */
virtual void Write(std::string const &content, double timestamp);

protected:
/** Constructor */
ConsoleLogOutput();

/** Destructor */
virtual ~ConsoleLogOutput();

private:

static SimpleFastMutexLock m_Mutex;
};

}

#endif //__itk_ConsoleLogOutput_h_
98 changes: 98 additions & 0 deletions Code/Common/itkFileLogOutput.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkFileLogOutput.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

#include<iostream>
#include"itkFileLogOutput.h"


namespace itk
{

/** Constructor */
FileLogOutput::FileLogOutput()
{
this->m_File = 0;
}

/** Destructor */
FileLogOutput::~FileLogOutput()
{
if( this->m_File )
{
this->m_File->close();
}
}


/** Set file stream */
void FileLogOutput::SetFile( FileType & FileStream )
{
this->m_File = &FileStream;
this->m_File->precision(15);
}


/** flush a buffer */
void FileLogOutput::Flush()
{
FileLogOutput::m_Mutex.Lock();
if( this->m_File )
{
this->m_File->flush();
}
FileLogOutput::m_Mutex.Unlock();
}


/** Write to multiple outputs */
void FileLogOutput::Write(double timestamp)
{
FileLogOutput::m_Mutex.Lock();
if( this->m_File )
{
(*this->m_File) << timestamp;
}
FileLogOutput::m_Mutex.Unlock();
}


/** Write to a buffer */
void FileLogOutput::Write( const std::string & content )
{
FileLogOutput::m_Mutex.Lock();
if( this->m_File )
{
(*this->m_File) << content;
}
FileLogOutput::m_Mutex.Unlock();
}


/** Write to a buffer */
void FileLogOutput::Write( const std::string & content, double timestamp )
{
FileLogOutput::m_Mutex.Lock();
if( this->m_File )
{
(*this->m_File) << timestamp << " : " << content;
}
FileLogOutput::m_Mutex.Unlock();
}


}

Loading

0 comments on commit e3e00ad

Please sign in to comment.