Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

RepeatGuardLogger.h

Go to the documentation of this file.
00001 #ifndef REPEATGUARDLOGGER_H 00002 #define REPEATGUARDLOGGER_H 00003 /******************************************************************************* 00004 * ALMA - Atacama Large Millimiter Array 00005 * (c) Associated Universities Inc., 2007 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * "@(#) $Id: RepeatGuardLogger.h,v 1.5 2007/03/23 09:50:06 nbarriga Exp $" 00022 * 00023 * who when what 00024 * -------- -------- ---------------------------------------------- 00025 * nbarriga 2007-02-26 created 00026 */ 00027 00028 /************************************************************************ 00029 * 00030 *---------------------------------------------------------------------- 00031 */ 00032 00033 #ifndef __cplusplus 00034 #error This is a C++ include file and cannot be used from plain C 00035 #endif 00036 00037 #include <acsutilTimeStamp.h> 00038 #include <loggingACSLogger.h> 00039 00040 #include "RepeatGuard.h" 00041 00042 00043 namespace Logging 00044 { 00045 00098 template <class ALogger> class RepeatGuardLogger : RepeatGuard 00099 { 00100 00101 private: 00102 00103 protected: 00104 00105 public: 00106 00113 RepeatGuardLogger(ACS::TimeInterval interval, 00114 unsigned int maxRepetitions=0); 00115 virtual ~RepeatGuardLogger(); 00116 00117 void log(ALogger &logger ); 00118 void log(Logging::Logger::LoggerSmartPtr &logger, Logging::BaseLog::Priority priority, 00119 const std::string &message, 00120 const std::string &file, 00121 unsigned long line, 00122 const std::string &method); 00123 void log(Logging::Logger::LoggerSmartPtr &logger, 00124 const Logging::BaseLog::LogRecord &lr); 00125 00126 void logAndIncrement(ALogger &logger ); 00127 void logAndIncrement(Logging::Logger::LoggerSmartPtr &logger, Logging::BaseLog::Priority priority, 00128 const std::string &message, 00129 const std::string &file, 00130 unsigned long line, 00131 const std::string &method); 00132 void logAndIncrement(Logging::Logger::LoggerSmartPtr &logger, 00133 const Logging::BaseLog::LogRecord &lr); 00134 00135 }; /* end RepeatGuardLogger */ 00136 00137 }; /* end namespace Logging */ 00138 00139 00140 /********************************************************* 00141 * @todo 00142 * Implementation of methods. 00143 * To be later on moved in .i file 00144 */ 00145 00146 template <class ALogger> 00147 Logging::RepeatGuardLogger<ALogger>::RepeatGuardLogger(ACS::TimeInterval interval, 00148 unsigned int maxRepetitions) : 00149 RepeatGuard(interval,maxRepetitions) 00150 { 00151 } 00152 00153 template <class ALogger> 00154 Logging::RepeatGuardLogger<ALogger>::~RepeatGuardLogger() 00155 { 00156 } 00157 00158 template <class ALogger> 00159 void Logging::RepeatGuardLogger<ALogger>::log(ALogger &logger ) 00160 { 00161 if(check()) 00162 { 00163 std::stringstream strstr; 00164 strstr << count(); 00165 00166 LoggingProxy::AddData("repeatCount", strstr.str().c_str() ); 00167 00168 logger.log(); 00169 } 00170 }; 00171 00172 template <class ALogger> 00173 void Logging::RepeatGuardLogger<ALogger>::log(Logging::Logger::LoggerSmartPtr &logger, 00174 Logging::BaseLog::Priority priority, 00175 const std::string &message, 00176 const std::string &file, 00177 unsigned long line, 00178 const std::string &method) 00179 { 00180 if(check()) 00181 { 00182 std::stringstream strstr; 00183 strstr << count(); 00184 00185 LoggingProxy::AddData("repeatCount", strstr.str().c_str() ); 00186 00187 logger->log(priority, message, 00188 file, line, method); 00189 } 00190 } 00191 00192 00193 template <class ALogger> 00194 void Logging::RepeatGuardLogger<ALogger>::log(Logging::Logger::LoggerSmartPtr &logger, 00195 const Logging::BaseLog::LogRecord &lr) 00196 { 00197 if(check()) 00198 { 00199 std::stringstream strstr; 00200 strstr << count(); 00201 00202 LoggingProxy::AddData("repeatCount", strstr.str().c_str() ); 00203 00204 logger->log(lr); 00205 } 00206 } 00207 template <class ALogger> 00208 void Logging::RepeatGuardLogger<ALogger>::logAndIncrement(ALogger &logger ) 00209 { 00210 if(checkAndIncrement()) 00211 { 00212 std::stringstream strstr; 00213 strstr << count(); 00214 00215 LoggingProxy::AddData("repeatCount", strstr.str().c_str() ); 00216 00217 logger.log(); 00218 } 00219 }; 00220 00221 template <class ALogger> 00222 void Logging::RepeatGuardLogger<ALogger>::logAndIncrement(Logging::Logger::LoggerSmartPtr &logger, 00223 Logging::BaseLog::Priority priority, 00224 const std::string &message, 00225 const std::string &file, 00226 unsigned long line, 00227 const std::string &method) 00228 { 00229 if(checkAndIncrement()) 00230 { 00231 std::stringstream strstr; 00232 strstr << count(); 00233 00234 LoggingProxy::AddData("repeatCount", strstr.str().c_str() ); 00235 00236 logger->log(priority, message, 00237 file, line, method); 00238 } 00239 } 00240 00241 00242 template <class ALogger> 00243 void Logging::RepeatGuardLogger<ALogger>::logAndIncrement(Logging::Logger::LoggerSmartPtr &logger, 00244 const Logging::BaseLog::LogRecord &lr) 00245 { 00246 if(checkAndIncrement()) 00247 { 00248 std::stringstream strstr; 00249 strstr << count(); 00250 00251 LoggingProxy::AddData("repeatCount", strstr.str().c_str() ); 00252 00253 logger->log(lr); 00254 } 00255 } 00256 00257 00258 #endif

Generated on Thu Apr 30 02:30:52 2009 for ACS C++ API by doxygen 1.3.8