-
-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Classes for supporting Logging. These classes will facilitate de…
…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
Showing
19 changed files
with
1,949 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.