Jpp
JMessageScheduler.hh
Go to the documentation of this file.
1 #ifndef __JLOGGER__JMESSAGESCHEDULER__
2 #define __JLOGGER__JMESSAGESCHEDULER__
3 
5 #include "Jeep/JTimekeeper.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JLOGGER {}
13 namespace JPP { using namespace JLOGGER; }
14 
15 namespace JLOGGER {
16 
17  using JEEP::JTimekeeper;
18 
19 
20  /**
21  * Message logger with time scheduler.
22  * Messages will only be reported when the elapsed time since last message exceeds the specified time interval.
23  * The first message is always reported.
24  */
26  public JMessageLogger,
27  public JTimekeeper
28  {
29  public:
30  /**
31  * Default constructor.
32  */
35  JTimekeeper (),
36  credit (0)
37  {}
38 
39 
40  /**
41  * Constructor.
42  * The time is reset so that the first message is sent any way.
43  *
44  * \param logger logger
45  * \param timer timer
46  */
48  const JTimekeeper& timer) :
50  JTimekeeper (timer),
51  credit (1)
52  {
54  }
55 
56 
57  /**
58  * Set credit.
59  * Note that the maximal number of messages reported per interval time
60  * is equal to the credit which is set once at a time.
61  *
62  * \param credit credit
63  */
64  void setCredit(const int credit)
65  {
66  this->credit = credit;
67  }
68 
69  /**
70  * Report message.
71  *
72  * \param tag tag
73  * \param message message
74  */
75  virtual void typeout(const std::string& tag,
76  const std::string& message)
77  {
78  if (JTimekeeper::operator()()) {
79  reset();
80  }
81 
82  if (credit != 0) {
83 
84  JMessageLogger::typeout(tag, message);
85 
86  --credit;
87  }
88  }
89 
90 
91  /**
92  * Reset.
93  */
94  void reset()
95  {
97 
98  credit = 1;
99  }
100 
101  protected:
102  int credit;
103  };
104 }
105 
106 #endif
JLOGGER::JMessageLogger
Message logger.
Definition: JMessageLogger.hh:53
JLOGGER::JMessageScheduler::reset
void reset()
Reset.
Definition: JMessageScheduler.hh:94
JLOGGER::JMessageLogger::typeout
virtual void typeout(const std::string &tag, const std::string &message)
Report message.
Definition: JMessageLogger.hh:173
JEEP::JTimekeeper::reset
void reset()
Reset time.
Definition: JTimekeeper.hh:111
JLOGGER
Message logging.
Definition: JControlHostLogger.hh:14
JTimekeeper.hh
JLOGGER::JMessageScheduler::typeout
virtual void typeout(const std::string &tag, const std::string &message)
Report message.
Definition: JMessageScheduler.hh:75
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLOGGER::JMessageScheduler::setCredit
void setCredit(const int credit)
Set credit.
Definition: JMessageScheduler.hh:64
JLOGGER::JMessageScheduler::JMessageScheduler
JMessageScheduler()
Default constructor.
Definition: JMessageScheduler.hh:33
JEEP::JTimekeeper
Time keeper.
Definition: JTimekeeper.hh:34
JLOGGER::JMessageScheduler::credit
int credit
Definition: JMessageScheduler.hh:102
JLOGGER::JMessageScheduler
Message logger with time scheduler.
Definition: JMessageScheduler.hh:25
JLOGGER::JMessageScheduler::JMessageScheduler
JMessageScheduler(const JMessageLogger &logger, const JTimekeeper &timer)
Constructor.
Definition: JMessageScheduler.hh:47
JLOGGER::JMessageLogger::logger
JSharedPointer< JLogger > logger
Definition: JMessageLogger.hh:225
JMessageLogger.hh