Guard template class against log repetitions. More...
#include <RepeatGuardLogger.h>
Public Member Functions | |
RepeatGuardLogger (ACS::TimeInterval interval, unsigned int maxRepetitions=0) | |
virtual | ~RepeatGuardLogger () |
void | log (ALogger &logger) |
void | log (Logging::Logger::LoggerSmartPtr &logger, Logging::BaseLog::Priority priority, const std::string &message, const std::string &file, unsigned long line, const std::string &method) |
void | log (Logging::Logger::LoggerSmartPtr &logger, const Logging::BaseLog::LogRecord &lr) |
void | logAndIncrement (ALogger &logger) |
void | logAndIncrement (Logging::Logger::LoggerSmartPtr &logger, Logging::BaseLog::Priority priority, const std::string &message, const std::string &file, unsigned long line, const std::string &method) |
void | logAndIncrement (Logging::Logger::LoggerSmartPtr &logger, const Logging::BaseLog::LogRecord &lr) |
Guard template class against log repetitions.
This is a template class for guarding logs against logging too often. It inherits from RepeatGuard and adds different implementations of the log() method.
In all cases the log() method checks the guarding condition and, if it is the case, forwards the log() command to the given underlying logger object.
Before doing this, it adds the repeatCount additional data field to the log to notify that repeated logs have been skipped according to the guard condition.
Notes:
1. The implementation of the template exploits "partial template instantiation" (see Alexandrescu, Modern C++ Design, 1.8). The three signatures for the log() method are not supported by all loggers. What is important is that the log() signarues called for each specific instantiation of the template are supported.
Notice that the log() methods cannot be virtual, otherwise partial template instantiation would not work.
2. The logger object is passed as argument of the log method and not in the constructor of the guard to allow using the same guard with multiple loggers. This (in my opinion) extremely useful additionl flexibility comes to the price of one additional parameter in the function call.
3. Now only the log() method is implemented. This automaticaly increments the ocunter. It would be probably much better to have instead two methods (as was in the original design):
4. Here and in the base RepeatGuard class, the interval time is an integer in seconds. For consistency with the other interfaces it should be instead a TimeInterval (long long in 100ns()) as defined in acscommon.idl. If nobody vote against, I will change the signature.
Logging::RepeatGuardLogger< ALogger >::RepeatGuardLogger | ( | ACS::TimeInterval | interval, | |
unsigned int | maxRepetitions = 0 | |||
) |
Constructor
interval | minimum interval between allowing an action (i.e. check returns true) | |
maxRepetitions | override minimum interval if maxRepetitions is reached.(0 disables this feature) |
Logging::RepeatGuardLogger< ALogger >::~RepeatGuardLogger | ( | ) | [virtual] |
void Logging::RepeatGuardLogger< ALogger >::log | ( | ALogger & | logger | ) |
References LoggingProxy::AddData(), RepeatGuard::check(), and RepeatGuard::count().
void Logging::RepeatGuardLogger< ALogger >::log | ( | Logging::Logger::LoggerSmartPtr & | logger, | |
Logging::BaseLog::Priority | priority, | |||
const std::string & | message, | |||
const std::string & | file, | |||
unsigned long | line, | |||
const std::string & | method | |||
) |
References LoggingProxy::AddData(), RepeatGuard::check(), and RepeatGuard::count().
void Logging::RepeatGuardLogger< ALogger >::log | ( | Logging::Logger::LoggerSmartPtr & | logger, | |
const Logging::BaseLog::LogRecord & | lr | |||
) |
References LoggingProxy::AddData(), RepeatGuard::check(), and RepeatGuard::count().
void Logging::RepeatGuardLogger< ALogger >::logAndIncrement | ( | ALogger & | logger | ) |
References LoggingProxy::AddData(), RepeatGuard::checkAndIncrement(), and RepeatGuard::count().
void Logging::RepeatGuardLogger< ALogger >::logAndIncrement | ( | Logging::Logger::LoggerSmartPtr & | logger, | |
Logging::BaseLog::Priority | priority, | |||
const std::string & | message, | |||
const std::string & | file, | |||
unsigned long | line, | |||
const std::string & | method | |||
) |
References LoggingProxy::AddData(), RepeatGuard::checkAndIncrement(), and RepeatGuard::count().
void Logging::RepeatGuardLogger< ALogger >::logAndIncrement | ( | Logging::Logger::LoggerSmartPtr & | logger, | |
const Logging::BaseLog::LogRecord & | lr | |||
) |
References LoggingProxy::AddData(), RepeatGuard::checkAndIncrement(), and RepeatGuard::count().