00001 /* 00002 * synergy -- mouse and keyboard sharing utility 00003 * Copyright (C) 2002 Chris Schoeneman 00004 * 00005 * This package is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * found in the file COPYING that should have accompanied this file. 00008 * 00009 * This package is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 */ 00014 00015 #include "LogOutputters.h" 00016 #include "CArch.h" 00017 00018 // 00019 // CStopLogOutputter 00020 // 00021 00022 CStopLogOutputter::CStopLogOutputter() 00023 { 00024 // do nothing 00025 } 00026 00027 CStopLogOutputter::~CStopLogOutputter() 00028 { 00029 // do nothing 00030 } 00031 00032 void 00033 CStopLogOutputter::open(const char*) 00034 { 00035 // do nothing 00036 } 00037 00038 void 00039 CStopLogOutputter::close() 00040 { 00041 // do nothing 00042 } 00043 00044 void 00045 CStopLogOutputter::show(bool) 00046 { 00047 // do nothing 00048 } 00049 00050 bool 00051 CStopLogOutputter::write(ELevel, const char*) 00052 { 00053 return false; 00054 } 00055 00056 const char* 00057 CStopLogOutputter::getNewline() const 00058 { 00059 return ""; 00060 } 00061 00062 00063 // 00064 // CConsoleLogOutputter 00065 // 00066 00067 CConsoleLogOutputter::CConsoleLogOutputter() 00068 { 00069 // do nothing 00070 } 00071 00072 CConsoleLogOutputter::~CConsoleLogOutputter() 00073 { 00074 // do nothing 00075 } 00076 00077 void 00078 CConsoleLogOutputter::open(const char* title) 00079 { 00080 ARCH->openConsole(title); 00081 } 00082 00083 void 00084 CConsoleLogOutputter::close() 00085 { 00086 ARCH->closeConsole(); 00087 } 00088 00089 void 00090 CConsoleLogOutputter::show(bool showIfEmpty) 00091 { 00092 ARCH->showConsole(showIfEmpty); 00093 } 00094 00095 bool 00096 CConsoleLogOutputter::write(ELevel, const char* msg) 00097 { 00098 ARCH->writeConsole(msg); 00099 return true; 00100 } 00101 00102 const char* 00103 CConsoleLogOutputter::getNewline() const 00104 { 00105 return ARCH->getNewlineForConsole(); 00106 } 00107 00108 00109 // 00110 // CSystemLogOutputter 00111 // 00112 00113 CSystemLogOutputter::CSystemLogOutputter() 00114 { 00115 // do nothing 00116 } 00117 00118 CSystemLogOutputter::~CSystemLogOutputter() 00119 { 00120 // do nothing 00121 } 00122 00123 void 00124 CSystemLogOutputter::open(const char* title) 00125 { 00126 ARCH->openLog(title); 00127 } 00128 00129 void 00130 CSystemLogOutputter::close() 00131 { 00132 ARCH->closeLog(); 00133 } 00134 00135 void 00136 CSystemLogOutputter::show(bool showIfEmpty) 00137 { 00138 ARCH->showLog(showIfEmpty); 00139 } 00140 00141 bool 00142 CSystemLogOutputter::write(ELevel level, const char* msg) 00143 { 00144 IArchLog::ELevel archLogLevel; 00145 switch (level) { 00146 case CLog::kFATAL: 00147 case CLog::kERROR: 00148 archLogLevel = IArchLog::kERROR; 00149 break; 00150 00151 case CLog::kWARNING: 00152 archLogLevel = IArchLog::kWARNING; 00153 break; 00154 00155 case CLog::kNOTE: 00156 archLogLevel = IArchLog::kNOTE; 00157 break; 00158 00159 case CLog::kINFO: 00160 archLogLevel = IArchLog::kINFO; 00161 break; 00162 00163 default: 00164 archLogLevel = IArchLog::kDEBUG; 00165 break; 00166 00167 }; 00168 ARCH->writeLog(archLogLevel, msg); 00169 return true; 00170 } 00171 00172 const char* 00173 CSystemLogOutputter::getNewline() const 00174 { 00175 return ""; 00176 } 00177 00178 00179 // 00180 // CSystemLogger 00181 // 00182 00183 CSystemLogger::CSystemLogger(const char* title, bool blockConsole) : 00184 m_stop(NULL) 00185 { 00186 // redirect log messages 00187 if (blockConsole) { 00188 m_stop = new CStopLogOutputter; 00189 CLOG->insert(m_stop); 00190 } 00191 m_syslog = new CSystemLogOutputter; 00192 m_syslog->open(title); 00193 CLOG->insert(m_syslog); 00194 } 00195 00196 CSystemLogger::~CSystemLogger() 00197 { 00198 CLOG->remove(m_syslog); 00199 delete m_syslog; 00200 if (m_stop != NULL) { 00201 CLOG->remove(m_stop); 00202 delete m_stop; 00203 } 00204 } 00205 00206 00207 // 00208 // CBufferedLogOutputter 00209 // 00210 00211 CBufferedLogOutputter::CBufferedLogOutputter(UInt32 maxBufferSize) : 00212 m_maxBufferSize(maxBufferSize) 00213 { 00214 // do nothing 00215 } 00216 00217 CBufferedLogOutputter::~CBufferedLogOutputter() 00218 { 00219 // do nothing 00220 } 00221 00222 CBufferedLogOutputter::const_iterator 00223 CBufferedLogOutputter::begin() const 00224 { 00225 return m_buffer.begin(); 00226 } 00227 00228 CBufferedLogOutputter::const_iterator 00229 CBufferedLogOutputter::end() const 00230 { 00231 return m_buffer.end(); 00232 } 00233 00234 void 00235 CBufferedLogOutputter::open(const char*) 00236 { 00237 // do nothing 00238 } 00239 00240 void 00241 CBufferedLogOutputter::close() 00242 { 00243 // remove all elements from the buffer 00244 m_buffer.clear(); 00245 } 00246 00247 void 00248 CBufferedLogOutputter::show(bool) 00249 { 00250 // do nothing 00251 } 00252 00253 bool 00254 CBufferedLogOutputter::write(ELevel, const char* message) 00255 { 00256 while (m_buffer.size() >= m_maxBufferSize) { 00257 m_buffer.pop_front(); 00258 } 00259 m_buffer.push_back(CString(message)); 00260 return true; 00261 } 00262 00263 const char* 00264 CBufferedLogOutputter::getNewline() const 00265 { 00266 return ""; 00267 }