#ifndef __JLOGGER__JMESSAGESCHEDULER__ #define __JLOGGER__JMESSAGESCHEDULER__ #include "JLogger/JMessageLogger.hh" #include "Jeep/JTimekeeper.hh" /** * \author mdejong */ namespace JLOGGER {} namespace JPP { using namespace JLOGGER; } namespace JLOGGER { using JEEP::JTimekeeper; /** * Message logger with time scheduler. * Messages will only be reported when the elapsed time since last message exceeds the specified time interval. * The first message is always reported. */ class JMessageScheduler : public JMessageLogger, public JTimekeeper { public: /** * Default constructor. */ JMessageScheduler() : JMessageLogger(), JTimekeeper (), credit (0) {} /** * Constructor. * The time is reset so that the first message is sent any way. * * \param logger logger * \param timer timer */ JMessageScheduler(const JMessageLogger& logger, const JTimekeeper& timer) : JMessageLogger(logger), JTimekeeper (timer), credit (1) { JTimekeeper::reset(); } /** * Set credit. * Note that the maximal number of messages reported per interval time * is equal to the credit which is set once at a time. * * \param credit credit */ void setCredit(const int credit) { this->credit = credit; } /** * Report message. * * \param tag tag * \param message message */ virtual void typeout(const std::string& tag, const std::string& message) override { if (JTimekeeper::operator()()) { reset(); } if (credit != 0) { JMessageLogger::typeout(tag, message); --credit; } } /** * Reset. */ void reset() { JTimekeeper::reset(); credit = 1; } protected: int credit; }; } #endif