gramods
MessageSink.hh
1 
2 #ifndef GRAMODS_CORE_MESSAGESINK
3 #define GRAMODS_CORE_MESSAGESINK
4 
5 #include <gmCore/config.hh>
6 
7 #include <gmCore/ConsoleLevel.hh>
8 #include <gmCore/Object.hh>
9 #include <gmCore/OFactory.hh>
10 
11 #include <ostream>
12 #include <chrono>
13 
14 BEGIN_NAMESPACE_GMCORE;
15 
23  : public gmCore::Object {
24 
25 public:
26 
27  struct Message {
28 
29  typedef std::chrono::steady_clock clock;
30 
31  Message(ConsoleLevel level, std::string tag, std::string msg,
32  std::string file, int line, std::string function)
33  : level(level), tag(tag), message(msg),
34  source_data_available(true), file(file), line(line), function(function),
35  time_stamp(clock::now()) {}
36 
37  Message(ConsoleLevel level, std::string tag, std::string msg)
38  : level(level), tag(tag), message(msg),
39  source_data_available(false), file(""), line(0), function(""),
40  time_stamp(clock::now()) {}
41 
42  clock::duration getDuration() {
43  static clock::time_point start_time = clock::now();
44  return time_stamp - start_time;
45  }
46 
47  ConsoleLevel level;
48 
49  std::string tag;
50  std::string message;
51 
52  bool source_data_available;
53  std::string file;
54  int line;
55  std::string function;
56 
57  clock::time_point time_stamp;
58  };
59 
64  virtual void initialize() override;
65 
72  void setShowTime(bool on) {
73  show_time = on;
74  }
75 
81  virtual void output(Message msg) = 0;
82 
83  GM_OFI_DECLARE;
84 
85 protected:
86 
91  void outputMetadata(std::ostream &out, Message msg);
92 
93 private:
94 
95  bool show_time = false;
96 };
97 
98 END_NAMESPACE_GMCORE;
99 
100 #endif
This is the base type for back-ends taking care of information sent to the Console class.
Definition: MessageSink.hh:23
virtual void output(Message msg)=0
Outputs the provided message to the implementation specific channel.
void setShowTime(bool on)
Activate or deactivate the output of the time of each message.
Definition: MessageSink.hh:72
Base type for objects in the Gramods package for standardized handling of construction,...
Definition: Object.hh:42
Definition: MessageSink.hh:27