Go to the documentation of this file.00001 #ifndef REPEATGUARDLOGGER_H
00002 #define REPEATGUARDLOGGER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 };
00136
00137 };
00138
00139
00140
00141
00142
00143
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