source: trunk/FACT++/src/MessageImp.h

Last change on this file was 17341, checked in by tbretz, 8 years ago
Implemented an output if between two messages, the date changes. This makes it easier to follow a long log file.
File size: 4.2 KB
Line 
1#ifndef FACT_MessageImp
2#define FACT_MessageImp
3
4#include <string>
5#include <sstream>
6#include <iostream>
7
8class Time;
9
10class MessageImp
11{
12public:
13 /// Severity of a message
14 enum Severity
15 {
16 kMessage = 10, ///< Just a message, usually obsolete
17 kInfo = 20, ///< An info telling something which can be interesting to know
18 kWarn = 30, ///< A warning, things that somehow might result in unexpected or unwanted bahaviour
19 kError = 40, ///< Error, something unexpected happened, but can still be handled by the program
20 kAlarm = 45, ///< Error, something unexpected happened, but needs user intervention (i.e. it needs a signal to the user)
21 kFatal = 50, ///< An error which cannot be handled at all happend, the only solution is program termination
22 kComment = 90, ///< A comment which is always printed
23 kDebug = 99, ///< A message used for debugging only
24 };
25
26private:
27 std::ostream &fOut; /// The ostream to which by default Write redirects its output
28 uint32_t fLastMjd; /// Mjd of last message
29
30 int WriteImp(const Time &time, const std::string &txt, int qos=kMessage);
31
32public:
33 MessageImp(std::ostream &out=std::cout);
34 virtual ~MessageImp() { }
35
36 virtual void IndicateStateChange(const Time &, const std::string &) { }
37 void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state);
38 virtual int Write(const Time &time, const std::string &txt, int qos=kMessage);
39
40 int Update(const std::string &txt, int severity=kMessage);
41 int Update(const char *txt, int severity=kMessage) { return Update(std::string(txt), severity); }
42 int Update(const std::ostringstream &str, int severity=kMessage) { return Update(str.str(), severity); }
43// int Update(int qos, const char *fmt, ...);
44
45 int Debug(const std::string &str) { return Update(str, kDebug); }
46 int Message(const std::string &str) { return Update(str, kMessage); }
47 int Info(const std::string &str) { return Update(str, kInfo); }
48 int Warn(const std::string &str) { return Update(str, kWarn); }
49 int Error(const std::string &str) { return Update(str, kError); }
50 int Alarm(const std::string &str) { return Update(str, kAlarm); }
51 int Fatal(const std::string &str) { return Update(str, kFatal); }
52 int Comment(const std::string &str) { return Update(str, kComment); }
53
54 int Debug(const char *txt) { return Debug(std::string(txt)); }
55 int Message(const char *txt) { return Message(std::string(txt)); }
56 int Info(const char *txt) { return Info(std::string(txt)); }
57 int Warn(const char *txt) { return Warn(std::string(txt)); }
58 int Error(const char *txt) { return Error(std::string(txt)); }
59 int Alarm(const char *txt) { return Alarm(std::string(txt)); }
60 int Fatal(const char *txt) { return Fatal(std::string(txt)); }
61 int Comment(const char *txt) { return Comment(std::string(txt)); }
62
63 int Debug(const std::ostringstream &str) { return Debug(str.str()); }
64 int Message(const std::ostringstream &str) { return Message(str.str()); }
65 int Info(const std::ostringstream &str) { return Info(str.str()); }
66 int Warn(const std::ostringstream &str) { return Warn(str.str()); }
67 int Alarm(const std::ostringstream &str) { return Alarm(str.str()); }
68 int Error(const std::ostringstream &str) { return Error(str.str()); }
69 int Fatal(const std::ostringstream &str) { return Fatal(str.str()); }
70 int Comment(const std::ostringstream &str) { return Comment(str.str()); }
71
72 std::ostream &operator()() const { return fOut; }
73 std::ostream &Out() const { return fOut; }
74
75 virtual bool MessageQueueEmpty() const { return true; }
76};
77
78#endif
79
80// ***************************************************************************
81/** @fn MessageImp::IndicateStateChange(const Time &time, const std::string &server)
82
83This function is called to indicate a state change by StateChanged() to
84derived classes.
85
86@param time
87 Time at which the state change happened
88
89@param server
90 Server which emitted the state change
91
92**/
93// ***************************************************************************
Note: See TracBrowser for help on using the repository browser.