00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LogOutputters.h"
00020 #include "CArch.h"
00021 #include "TMethodJob.h"
00022
00023 #include <fstream>
00024
00025
00026
00027
00028 CStopLogOutputter::CStopLogOutputter()
00029 {
00030
00031 }
00032
00033 CStopLogOutputter::~CStopLogOutputter()
00034 {
00035
00036 }
00037
00038 void
00039 CStopLogOutputter::open(const char*)
00040 {
00041
00042 }
00043
00044 void
00045 CStopLogOutputter::close()
00046 {
00047
00048 }
00049
00050 void
00051 CStopLogOutputter::show(bool)
00052 {
00053
00054 }
00055
00056 bool
00057 CStopLogOutputter::write(ELevel, const char*)
00058 {
00059 return false;
00060 }
00061
00062
00063
00064
00065
00066
00067 CConsoleLogOutputter::CConsoleLogOutputter()
00068 {
00069 }
00070
00071 CConsoleLogOutputter::~CConsoleLogOutputter()
00072 {
00073 }
00074
00075 void
00076 CConsoleLogOutputter::open(const char* title)
00077 {
00078 ARCH->openConsole(title);
00079 }
00080
00081 void
00082 CConsoleLogOutputter::close()
00083 {
00084 ARCH->closeConsole();
00085 }
00086
00087 void
00088 CConsoleLogOutputter::show(bool showIfEmpty)
00089 {
00090 ARCH->showConsole(showIfEmpty);
00091 }
00092
00093 bool
00094 CConsoleLogOutputter::write(ELevel level, const char* msg)
00095 {
00096 ARCH->writeConsole(level, msg);
00097 return true;
00098 }
00099
00100 void
00101 CConsoleLogOutputter::flush()
00102 {
00103
00104 }
00105
00106
00107
00108
00109
00110
00111 CSystemLogOutputter::CSystemLogOutputter()
00112 {
00113
00114 }
00115
00116 CSystemLogOutputter::~CSystemLogOutputter()
00117 {
00118
00119 }
00120
00121 void
00122 CSystemLogOutputter::open(const char* title)
00123 {
00124 ARCH->openLog(title);
00125 }
00126
00127 void
00128 CSystemLogOutputter::close()
00129 {
00130 ARCH->closeLog();
00131 }
00132
00133 void
00134 CSystemLogOutputter::show(bool showIfEmpty)
00135 {
00136 ARCH->showLog(showIfEmpty);
00137 }
00138
00139 bool
00140 CSystemLogOutputter::write(ELevel level, const char* msg)
00141 {
00142 ARCH->writeLog(level, msg);
00143 return true;
00144 }
00145
00146
00147
00148
00149
00150 CSystemLogger::CSystemLogger(const char* title, bool blockConsole) :
00151 m_stop(NULL)
00152 {
00153
00154 if (blockConsole) {
00155 m_stop = new CStopLogOutputter;
00156 CLOG->insert(m_stop);
00157 }
00158 m_syslog = new CSystemLogOutputter;
00159 m_syslog->open(title);
00160 CLOG->insert(m_syslog);
00161 }
00162
00163 CSystemLogger::~CSystemLogger()
00164 {
00165 CLOG->remove(m_syslog);
00166 delete m_syslog;
00167 if (m_stop != NULL) {
00168 CLOG->remove(m_stop);
00169 delete m_stop;
00170 }
00171 }
00172
00173
00174
00175
00176
00177
00178 CBufferedLogOutputter::CBufferedLogOutputter(UInt32 maxBufferSize) :
00179 m_maxBufferSize(maxBufferSize)
00180 {
00181
00182 }
00183
00184 CBufferedLogOutputter::~CBufferedLogOutputter()
00185 {
00186
00187 }
00188
00189 CBufferedLogOutputter::const_iterator
00190 CBufferedLogOutputter::begin() const
00191 {
00192 return m_buffer.begin();
00193 }
00194
00195 CBufferedLogOutputter::const_iterator
00196 CBufferedLogOutputter::end() const
00197 {
00198 return m_buffer.end();
00199 }
00200
00201 void
00202 CBufferedLogOutputter::open(const char*)
00203 {
00204
00205 }
00206
00207 void
00208 CBufferedLogOutputter::close()
00209 {
00210
00211 m_buffer.clear();
00212 }
00213
00214 void
00215 CBufferedLogOutputter::show(bool)
00216 {
00217
00218 }
00219
00220 bool
00221 CBufferedLogOutputter::write(ELevel, const char* message)
00222 {
00223 while (m_buffer.size() >= m_maxBufferSize) {
00224 m_buffer.pop_front();
00225 }
00226 m_buffer.push_back(CString(message));
00227 return true;
00228 }
00229
00230
00231
00232
00233
00234
00235 CFileLogOutputter::CFileLogOutputter(const char* logFile)
00236 {
00237 assert(logFile != NULL);
00238 m_fileName = logFile;
00239 }
00240
00241 CFileLogOutputter::~CFileLogOutputter()
00242 {
00243 }
00244
00245 bool
00246 CFileLogOutputter::write(ELevel level, const char *message)
00247 {
00248 std::ofstream m_handle;
00249 m_handle.open(m_fileName.c_str(), std::fstream::app);
00250 if (m_handle.is_open() && m_handle.fail() != true) {
00251 m_handle << message << std::endl;
00252 }
00253 m_handle.close();
00254
00255 return true;
00256 }
00257
00258 void
00259 CFileLogOutputter::open(const char *title) {}
00260
00261 void
00262 CFileLogOutputter::close() {}
00263
00264 void
00265 CFileLogOutputter::show(bool showIfEmpty) {}
00266
00267
00268
00269
00270
00271 CMesssageBoxLogOutputter::CMesssageBoxLogOutputter()
00272 {
00273
00274 }
00275
00276 CMesssageBoxLogOutputter::~CMesssageBoxLogOutputter()
00277 {
00278
00279 }
00280
00281 void
00282 CMesssageBoxLogOutputter::open(const char* title)
00283 {
00284
00285 }
00286
00287 void
00288 CMesssageBoxLogOutputter::close()
00289 {
00290
00291 }
00292
00293 void
00294 CMesssageBoxLogOutputter::show(bool showIfEmpty)
00295 {
00296
00297 }
00298
00299 bool
00300 CMesssageBoxLogOutputter::write(ELevel level, const char* msg)
00301 {
00302
00303 if (level > kERROR) {
00304 return true;
00305 }
00306
00307 #if SYSAPI_WIN32
00308 MessageBox(NULL, msg, CLOG->getFilterName(level), MB_OK);
00309 #endif
00310
00311 return true;
00312 }