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 m_bTruncate(FALSE) 00059 { 00060 //Create the CS 00061 m_pCSection=COSManager::CreateCriticalSection(); 00062 }
Definition at line 64 of file FileLog.cpp. 00065 { 00066 try 00067 { 00068 //Close the file 00069 fclose(m_pFile); 00070 00071 //Delete the CS 00072 delete m_pCSection; 00073 } 00074 ERROR_UNKNOWN("~CFileLog") 00075 }
Member Function Documentation
Definition at line 77 of file FileLog.cpp. 00078 { 00079 //Open's the log file 00080 try 00081 { 00082 //Check if the file is open 00083 if (m_pFile) 00084 //close is 00085 fclose(m_pFile); 00086 00087 //Which open mode 00088 BOOL bTruncate; 00089 bTruncate=FALSE; 00090 00091 //Do we need to get the file size 00092 if (m_dwMaxLogSize) 00093 { 00094 //Open the file 00095 HANDLE hFile; 00096 hFile=CreateFile(rFileName.c_str(), 00097 GENERIC_READ, 00098 FILE_SHARE_READ, 00099 NULL, 00100 OPEN_EXISTING, 00101 FILE_ATTRIBUTE_NORMAL, 00102 NULL); 00103 00104 //Do we have it? 00105 if (hFile!=INVALID_HANDLE_VALUE) 00106 { 00107 //Get the file size 00108 DWORD dwSize; 00109 dwSize=GetFileSize(hFile, 00110 NULL); 00111 00112 //Close the file 00113 CloseHandle(hFile); 00114 00115 //Is it bigger 00116 if (dwSize>m_dwMaxLogSize) 00117 bTruncate=TRUE; 00118 } 00119 } 00120 00121 //Now open the file 00122 if (!bTruncate) 00123 m_pFile=fopen(rFileName.c_str(),"at"); 00124 else 00125 m_pFile=fopen(rFileName.c_str(),"wt"); 00126 00127 //Save the file name 00128 m_sFileName=rFileName; 00129 00130 //Did we manage to open it? 00131 if (!m_pFile) 00132 return FALSE; 00133 else 00134 return TRUE; 00135 } 00136 ERROR_UNKNOWN_RETURN("ReportError",FALSE) 00137 }
Implements CErrorHandler::CErrorHandler::CErrorLog. Definition at line 177 of file FileLog.cpp. 00178 { 00179 WriteLog(rError); 00180 }
Definition at line 139 of file FileLog.cpp. 00140 { 00141 try 00142 { 00143 #ifdef _DEBUG 00144 m_aLog.WriteLog(rData); 00145 #endif 00146 //Lock it 00147 CCriticalAutoRelease aRelease(m_pCSection); 00148 00149 //Write to log 00150 fprintf(m_pFile,"%s\n",rData.c_str()); 00151 00152 //If error, or auto flush - then flush the data 00153 if (GetAutoFlush()) 00154 fflush(m_pFile); 00155 00156 //Do we need to truncate? 00157 if (m_bTruncate && 00158 m_dwMaxLogSize && 00159 ftell(m_pFile)>m_dwMaxLogSize) 00160 { 00161 //Reopen and close the log 00162 //Reinitialize if 00163 Initialize(m_sFileName); 00164 00165 //Rewrite to the file 00166 WriteLog(CErrorHandler::FormatData("CFileLog", 00167 "WriteLog", 00168 "Log truncated!")); 00169 } 00170 00171 //Done 00172 return true; 00173 } 00174 ERROR_UNKNOWN_RETURN("WriteLog",false) 00175 }
Implements CErrorHandler::CErrorHandler::CErrorLog. Definition at line 182 of file FileLog.cpp. 00183 { 00184 WriteLog(rMessage); 00185 }
The documentation for this class was generated from the following files: |