00001
00044
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <string.h>
00048 #include <stdarg.h>
00049 #include "CLogger.h"
00050
00051
00057
00058 CLogger* g_pGlobalLog = 0;
00059
00060
00061
00067
00068 bool CLoggerGlobalLogExists(void)
00069 {
00070 if(g_pGlobalLog != 0)
00071 return true;
00072 return false;
00073 }
00074
00075
00076
00082
00083 CLogger::CLogger(char* pcLogFileName)
00084 {
00085 m_pcLogFileName = new char [ strlen(pcLogFileName) + 1 ];
00086 strcpy(m_pcLogFileName, pcLogFileName);
00087 m_hLogFile = fopen(m_pcLogFileName, "w");
00088 LogStart();
00089 LogMessage("Log Started.");
00090 LoggingEnabled(true);
00091 }
00092
00093
00094
00098
00099 void CLogger::LogStart(void)
00100 {
00101 LogEntry("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
00102 LogEntry("<log>\n");
00103 }
00104
00105
00106
00110
00111 void CLogger::LogEnd(void)
00112 {
00113 LogEntry("</log>\n");
00114 }
00115
00116
00117
00121
00122 CLogger::~CLogger()
00123 {
00124 fclose(m_hLogFile);
00125 delete m_pcLogFileName;
00126 }
00127
00128
00129
00133
00134 void CLogger::LoggingEnabled(bool _bLog)
00135 {
00136 m_bLoggingEnabled = _bLog;
00137 if(_bLog)
00138 LogEntry("<message text=\"Logging Enabled.\" />\n");
00139 else
00140 LogEntry("<message text=\"Logging Disabled.\" />\n");
00141 }
00142
00143
00144
00151
00152 void CLogger::LogEntry(const char *pcFormat, ...)
00153 {
00154 if(m_hLogFile==0)
00155 return;
00156
00157 int iLen;
00158
00159 va_list argList;
00160
00161 va_start(argList, pcFormat);
00162 iLen = vsprintf(m_acTemp, pcFormat, argList);
00163 va_end(argList);
00164
00165 fprintf(m_hLogFile, m_acTemp);
00166 }
00167
00168
00169
00175
00176 void CLogger::LogMessage(const char *pcFormat, ...)
00177 {
00178 if(!m_bLoggingEnabled)
00179 return;
00180
00181 int iLen;
00182
00183 va_list argList;
00184 char acTemp[256];
00185
00186 va_start(argList, pcFormat);
00187 iLen = vsprintf(acTemp, pcFormat, argList);
00188 va_end(argList);
00189
00190 LogEntry("<message text=\"%s\" />\n", acTemp);
00191 }
00192
00193
00194
00195
00201
00202 void CLogger::LogFunction(const char *pcFormat, ...)
00203 {
00204 if(!m_bLoggingEnabled)
00205 return;
00206
00207 int iLen;
00208
00209 va_list argList;
00210 char acTemp[256];
00211
00212 va_start(argList, pcFormat);
00213 iLen = vsprintf(acTemp, pcFormat, argList);
00214 va_end(argList);
00215
00216 LogEntry("<function name=\"%s\" />\n", acTemp);
00217 }
00218
00219
00220
00226
00227 void CLogger::LogError(const char *pcFormat, ...)
00228 {
00229 if(!m_bLoggingEnabled)
00230 return;
00231
00232 int iLen;
00233
00234 va_list argList;
00235 char acTemp[256];
00236
00237 va_start(argList, pcFormat);
00238 iLen = vsprintf(acTemp, pcFormat, argList);
00239 va_end(argList);
00240
00241 LogEntry("<error text=\"%s\" />\n", acTemp);
00242 }
00243