CFileLog Class Reference#include <FileLog.h>
Inheritance diagram for CFileLog:
![]()
Collaboration diagram for CFileLog:
![]()
Detailed DescriptionDefinition at line 55 of file FileLog.h. Constructor & Destructor Documentation
Definition at line 54 of file FileLog.cpp. 00054 : CErrorHandler::CErrorLog(), 00055 m_pFile(NULL), 00056 m_pCSection(NULL), 00057 m_dwMaxLogSize(5000000) 00058 { 00059 //Create the CS 00060 m_pCSection=COSManager::CreateCriticalSection(); 00061 }
Definition at line 63 of file FileLog.cpp. 00064 { 00065 //Close the file 00066 fclose(m_pFile); 00067 00068 //Delete the CS 00069 delete m_pCSection; 00070 }
Member Function Documentation
Definition at line 72 of file FileLog.cpp. 00073 { 00074 //Open's the log file 00075 try 00076 { 00077 //Check if the file is open 00078 if (m_pFile) 00079 //close is 00080 fclose(m_pFile); 00081 00082 //Which open mode 00083 BOOL bTruncate; 00084 bTruncate=FALSE; 00085 00086 //Do we need to get the file size 00087 if (m_dwMaxLogSize) 00088 { 00089 //Open the file 00090 HANDLE hFile; 00091 hFile=CreateFile(rFileName.c_str(), 00092 GENERIC_READ, 00093 FILE_SHARE_READ, 00094 NULL, 00095 OPEN_EXISTING, 00096 FILE_ATTRIBUTE_NORMAL, 00097 NULL); 00098 00099 //Do we have it? 00100 if (hFile!=INVALID_HANDLE_VALUE) 00101 { 00102 //Get the file size 00103 DWORD dwSize; 00104 dwSize=GetFileSize(hFile, 00105 NULL); 00106 00107 //Close the file 00108 CloseHandle(hFile); 00109 00110 //Is it bigger 00111 if (dwSize>m_dwMaxLogSize) 00112 bTruncate=FALSE; 00113 } 00114 } 00115 00116 //Now open the file 00117 if (!bTruncate) 00118 m_pFile=fopen(rFileName.c_str(),"at"); 00119 else 00120 m_pFile=fopen(rFileName.c_str(),"wt"); 00121 00122 //Did we manage to open it? 00123 if (!m_pFile) 00124 return FALSE; 00125 else 00126 return TRUE; 00127 } 00128 ERROR_UNKNOWN_RETURN("ReportError",FALSE) 00129 }
Implements CErrorHandler::CErrorHandler::CErrorLog. Definition at line 191 of file FileLog.cpp. 00194 { 00195 //Delegate call 00196 WriteLog(rClass, 00197 rMethod, 00198 rMessage, 00199 CErrorHandler::lpError); 00200 }
Definition at line 131 of file FileLog.cpp. 00135 { 00136 try 00137 { 00138 #ifdef _DEBUG 00139 m_aLog.WriteLog(rClass, 00140 rMethod, 00141 rMessage, 00142 aPriority); 00143 #endif 00144 //Our error string 00145 std::string sPrefix; 00146 00147 //Our string to print 00148 switch (aPriority) 00149 { 00150 case CErrorHandler::lpMessage: 00151 sPrefix="***MESSAGE*** "; 00152 break; 00153 case CErrorHandler::lpCritical: 00154 sPrefix="***CRITICAL*** "; 00155 break; 00156 case CErrorHandler::lpError: 00157 sPrefix="***ERROR*** "; 00158 break; 00159 } 00160 00161 //Lock it 00162 CCriticalAutoRelease aRelease(m_pCSection); 00163 00164 //Do we have a prefix 00165 if (!sPrefix.empty()) 00166 fprintf(m_pFile,"%s",sPrefix.c_str()); 00167 00168 //First write time 00169 char tmpbuf[128]; 00170 00171 //Get data 00172 _strdate(tmpbuf); 00173 fprintf(m_pFile,"%s ",tmpbuf); 00174 00175 _strtime(tmpbuf); 00176 fprintf(m_pFile,"%s: ",tmpbuf); 00177 00178 //Write to log 00179 fprintf(m_pFile,"%s, %s, %s\n",rClass.c_str(), 00180 rMethod.c_str(), 00181 rMessage.c_str()); 00182 00183 //If error, or auto flush - then flush the data 00184 if (aPriority==CErrorHandler::lpError || 00185 GetAutoFlush()) 00186 fflush(m_pFile); 00187 } 00188 ERROR_UNKNOWN("WriteLog") 00189 }
Implements CErrorHandler::CErrorHandler::CErrorLog. Definition at line 202 of file FileLog.cpp. 00206 { 00207 //Delegate call 00208 WriteLog(rClass, 00209 rMethod, 00210 rMessage, 00211 aPriority); 00212 }
The documentation for this class was generated from the following files: |