log_event.h
Go to the documentation of this file.
1 // Log event with metadata
2 // Author: Max Schwarz <max.schwarz@ais.uni-bonn.de>
3 
4 #ifndef ROSMON_LOG_EVENT_H
5 #define ROSMON_LOG_EVENT_H
6 
7 #include <string>
8 #include <sstream>
9 
10 namespace rosmon
11 {
12 
13 struct LogEvent
14 {
15 public:
16  enum class Type
17  {
21  Raw,
22 
23  Debug,
24  Info,
25  Warning,
26  Error
27  };
28 
29  enum class Channel
30  {
31  NotApplicable,
32  Stdout,
33  Stderr
34  };
35 
36  LogEvent(std::string source, std::string message, Type type = Type::Raw)
37  : source{std::move(source)}, message{std::move(message)}, type{type}
38  {}
39 
40  std::string coloredString() const
41  {
42  auto colorize = [](const char* prefix, const std::string& str){
43  std::stringstream ss;
44  ss << prefix << str << "\e[0m";
45  return ss.str();
46  };
47 
48  switch(type)
49  {
50  case Type::Raw: return message;
51  case Type::Debug: return colorize("\e[32m", message);
52  case Type::Info: return colorize("\e[0m", message);
53  case Type::Warning: return colorize("\e[33m", message);
54  case Type::Error: return colorize("\e[31m", message);
55  }
56 
57  return message;
58  }
59 
60  std::string source;
61  std::string message;
63  bool muted = false;
65  bool showStdout = true;
66 };
67 
68 }
69 
70 #endif
Channel channel
Definition: log_event.h:64
std::string source
Definition: log_event.h:60
LogEvent(std::string source, std::string message, Type type=Type::Raw)
Definition: log_event.h:36
std::string coloredString() const
Definition: log_event.h:40
std::string message
Definition: log_event.h:61


rosmon_core
Author(s): Max Schwarz
autogenerated on Fri Jun 16 2023 02:15:06