00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <UnwrittenLogfileManager.hpp>
00021 #include <assert.h>
00022
00023
00024
00025
00026 UnwrittenLogfileManager * UnwrittenLogfileManager::m_pInstance = NULL;
00027
00028 UnwrittenLogfileManager::UnwrittenLogfileManager()
00029 {
00030 }
00031
00032 UnwrittenLogfileManager::~UnwrittenLogfileManager()
00033 {
00034 }
00035
00036 UnwrittenLogfileManager * UnwrittenLogfileManager::GetInstance()
00037 {
00038 if( UnwrittenLogfileManager::m_pInstance == NULL )
00039 UnwrittenLogfileManager::m_pInstance = new UnwrittenLogfileManager();
00040 return( UnwrittenLogfileManager::m_pInstance );
00041 }
00042
00043 bool UnwrittenLogfileManager::ShouldPrintMessageType()
00044 {
00045 return( this->m_bPrintMessageType );
00046 }
00047
00048 void UnwrittenLogfileManager::ShouldPrintMessageType( bool bShouldPrint )
00049 {
00050 this->m_bPrintMessageType = bShouldPrint;
00051 }
00052
00053 void UnwrittenLogfileManager::CloseLogfile( const std::string & szFilename )
00054 {
00055
00056 if( this->m_pLogfiles.find( szFilename ) == this->m_pLogfiles.end() )
00057 return;
00058
00059
00060 std::map< std::string, UnwrittenLogfile * >::const_iterator i = this->m_pLogfiles.find( szFilename );
00061
00062
00063 UnwrittenLogfile * pLogfile = static_cast< UnwrittenLogfile * >( i->second );
00064
00065
00066 pLogfile->Dispose();
00067 delete( pLogfile );
00068
00069
00070 this->m_pLogfiles.erase( szFilename );
00071 }
00072
00073 void UnwrittenLogfileManager::CloseLogfile( const UnwrittenLogfile * pLogfile )
00074 {
00075
00076 this->CloseLogfile( pLogfile->m_szLogfileName );
00077 }
00078
00079 void UnwrittenLogfileManager::SetDefaultLoggingType( UnwrittenLogfile::UnwrittenLoggingType newDefaultType )
00080 {
00081
00082 this->m_eDefaultLoggingType = newDefaultType;
00083 }
00084
00085 UnwrittenLogfile::UnwrittenLoggingType UnwrittenLogfileManager::GetDefaultLoggingType()
00086 {
00087
00088 return( this->m_eDefaultLoggingType );
00089 }
00090
00091 UnwrittenLogfile * UnwrittenLogfileManager::GetLogfile( const std::string & szFilename )
00092 {
00093
00094 if( this->m_pLogfiles.find( szFilename ) != this->m_pLogfiles.end() )
00095 {
00096
00097 std::map< std::string, UnwrittenLogfile * >::const_iterator i = this->m_pLogfiles.find( szFilename );
00098
00099
00100 UnwrittenLogfile * pLogfile = static_cast< UnwrittenLogfile * >( i->second );
00101
00102
00103 return( pLogfile );
00104 }
00105
00106
00107
00108
00109 UnwrittenLogfile * pLogfile = new UnwrittenLogfile( szFilename, this->m_bPrintMessageType );
00110 pLogfile->SetLoggingType( this->m_eDefaultLoggingType );
00111
00112
00113 this->m_pLogfiles[ szFilename ] = pLogfile;
00114
00115
00116 return( pLogfile );
00117 }
00118
00119 void UnwrittenLogfileManager::WriteToAllFiles( UnwrittenLogfile::UnwrittenLoggingType typeOfMsg, const std::string & szText, bool bNewLine )
00120 {
00121
00122 std::map< std::string, UnwrittenLogfile * >::const_iterator i = this->m_pLogfiles.begin();
00123
00124
00125 while( i != this->m_pLogfiles.end() )
00126 {
00127
00128 UnwrittenLogfile * pCurrentLogfile = static_cast< UnwrittenLogfile * >( i->second );
00129
00130
00131 if( bNewLine )
00132 pCurrentLogfile->WriteLine( typeOfMsg, szText.c_str() );
00133
00134
00135 else
00136 pCurrentLogfile->Write( typeOfMsg, szText.c_str() );
00137
00138
00139 ++i;
00140 }
00141 }
00142
00143 void UnwrittenLogfileManager::FlushAllFiles()
00144 {
00145
00146 std::map< std::string, UnwrittenLogfile * >::const_iterator i = this->m_pLogfiles.begin();
00147
00148
00149 while( i != this->m_pLogfiles.end() )
00150 {
00151
00152 UnwrittenLogfile * pCurrentLogfile = static_cast< UnwrittenLogfile * >( i->second );
00153
00154 #if defined(_DEBUG)
00155
00156 pCurrentLogfile->WriteLine( UnwrittenLogfile::UnwrittenDebug, "UnwrittenLogfileManager Synchronization Event: Flushing all logfiles!" );
00157 #endif
00158
00159
00160 pCurrentLogfile->Flush();
00161
00162
00163
00164 ++i;
00165 }
00166 }
00167
00168 size_t UnwrittenLogfileManager::GetManagedLogfiles()
00169 {
00170 return( this->m_pLogfiles.size() );
00171 }