TerminalOutput.h
1 
10 #ifndef WRENCH_S4U_COLORLOGGING_H
11 #define WRENCH_S4U_COLORLOGGING_H
12 
13 #include <map>
14 
15 #include <simgrid/s4u/Actor.hpp>
16 #include <xbt/log.h>
17 
18 #include <iostream>
19 
20 namespace wrench {
21 
22 
23 /* Wrappers around XBT_* macros, using a bit of those macro's internal magic as well
24  * to avoid generating useless (but space consuming) color ASCII codes
25  */
26 
27 #define WRENCH_LOG_CATEGORY(cname, desc) XBT_LOG_NEW_DEFAULT_CATEGORY(cname, desc)
28 
29 #define WRENCH_INFO(...); \
30  if (_XBT_LOG_ISENABLEDV((*_simgrid_log_category__default), xbt_log_priority_info)) { \
31  wrench::TerminalOutput::beginThisProcessColor(); \
32  XBT_INFO(__VA_ARGS__) ; \
33  wrench::TerminalOutput::endThisProcessColor(); \
34  }
35 
36 #define WRENCH_DEBUG(...); \
37  if (_XBT_LOG_ISENABLEDV((*_simgrid_log_category__default), xbt_log_priority_debug)) { \
38  wrench::TerminalOutput::beginThisProcessColor(); \
39  XBT_DEBUG(__VA_ARGS__) ; \
40  wrench::TerminalOutput::endThisProcessColor(); \
41  }
42 
43 #define WRENCH_WARN(...); \
44  if (_XBT_LOG_ISENABLEDV((*_simgrid_log_category__default), xbt_log_priority_warning)) { \
45  wrench::TerminalOutput::beginThisProcessColor(); \
46  XBT_WARN(__VA_ARGS__) ; \
47  wrench::TerminalOutput::endThisProcessColor(); \
48  }
49 
50  /***********************/
52  /***********************/
53 
58 
59  public:
60 
62  enum Color {
79  };
80 
81  static void setThisProcessLoggingColor(Color color);
82 
83 
84 
85  /***********************/
87  /***********************/
88 
89  static void beginThisProcessColor();
90 
91  static void endThisProcessColor();
92 
93  static void disableColor();
94 
95  static void disableLog();
96 
97  /***********************/
99  /***********************/
100 
101  private:
102 
103  static const char * color_codes[];
104 
105  static std::map<simgrid::s4u::Actor *, std::string> colormap;
106 
107  static std::string getThisProcessLoggingColor();
108 
109  static bool color_enabled;
110 
111  };
112 
113  /***********************/
115  /***********************/
116 };
117 
118 
119 #endif //WRENCH_S4U_COLORLOGGING_H
static void setThisProcessLoggingColor(Color color)
Set the color of log messages printed to the terminal.
Definition: TerminalOutput.cpp:36
@ COLOR_CYAN
Cyan text.
Definition: TerminalOutput.h:76
@ COLOR_GREEN
Green text.
Definition: TerminalOutput.h:68
Color
Terminal output color enum.
Definition: TerminalOutput.h:62
@ COLOR_RED
Red text.
Definition: TerminalOutput.h:66
@ COLOR_WHITE
White text.
Definition: TerminalOutput.h:78
Definition: Alarm.cpp:20
@ COLOR_BLACK
Black text.
Definition: TerminalOutput.h:64
@ COLOR_YELLOW
Yellow text.
Definition: TerminalOutput.h:70
Color-enabling wrappers around Simgrid's XBT_INFO, XBT_DEBUG, XBT_WARN logging macros.
Definition: TerminalOutput.h:57
@ COLOR_MAGENTA
Magenta text.
Definition: TerminalOutput.h:74
@ COLOR_BLUE
Blue text.
Definition: TerminalOutput.h:72