1 /*=========================================================================
4 Module: $RCSfile: gdcmDebug.cxx,v $
6 Date: $Date: 2007/05/23 14:18:08 $
7 Version: $Revision: 1.31 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDebug.h"
20 #include "gdcmCommandManager.h"
24 namespace GDCM_NAME_SPACE
26 //-----------------------------------------------------------------------------
27 // Warning message level to be displayed
28 const int Debug::LINE_LENGTH = 79;
30 bool Debug::DebugFlag = false;
31 bool Debug::LogFlag = false;
32 bool Debug::WarningFlag = false;
33 bool Debug::OutputToFile = false;
35 std::ofstream Debug::OutputFileStream;
36 std::ostream &Debug::StandardStream = std::cerr;
38 //-----------------------------------------------------------------------------
39 // Constructor / Destructor
46 if ( OutputFileStream.is_open() )
47 OutputFileStream.close();
50 //-----------------------------------------------------------------------------
53 * \brief Sets both the debug flag and warning flag
54 * (both used for debugging purpose)
55 * @param flag Set the debug flag and warning flag
57 void Debug::SetDebugFlag (bool flag)
59 // To help tracking a bug, both flags are necessary
65 * \brief Sets the warning flag
66 * @param flag Set the warning flag
68 void Debug::SetWarningFlag (bool flag)
70 // Cannot unset Warning flag if Debug flag is on or if LogFlag is on.
73 if (DebugFlag == true)
82 * \brief Sets the log flag
83 * @param flag Set the log flag
85 void Debug::SetLogFlag (bool flag)
87 // To log oddities, both flags are necessary
94 * @param flag whether we want to redirect to file
96 void Debug::SetOutputToFile (bool flag)
102 * \brief Accessor to know whether debug info are redirected to file
104 bool Debug::GetOutputToFile ()
110 * \brief Set the filename the debug stream should be redirect to
111 * Settting a filename also sets DebugToFile to true
112 * @param filename File to redirect debug info
113 * Absolutely nothing is check. You have to pass in
116 void Debug::SetOutputFileName (std::string const &filename)
118 OutputToFile = true; // Just in case ...
119 DebugFlag = true; // Just in case ...
120 if ( OutputFileStream.is_open() )
121 OutputFileStream.close();
122 OutputFileStream.open( filename.c_str() );
126 * \brief Internal use only. Allow us to retrieve the static from anywhere
130 std::ostream &Debug::GetOutput ()
133 return OutputFileStream;
135 return StandardStream;
138 void Debug::SendToOutput(unsigned int type,std::string const &msg,const Base *object)
141 if( type != CMD_DEBUG && type != CMD_ASSERT )
142 executed=CommandManager::ExecuteCommandConst(object,type,msg);
145 GetOutput() << Command::GetCommandAsString(type) << ": " << msg;
148 //-----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
154 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
158 } // end namespace gdcm