SENSEI
A frame work for generic in situ analytics
Error.h
1 #ifndef sensei_Common_h
2 #define sensei_Common_h
3 
4 #include "senseiConfig.h"
5 #include <iostream>
6 
7 namespace sensei
8 {
9 // detect if we are writing to a tty, if not then
10 // we should not use ansi color codes
11 SENSEI_EXPORT int haveTty();
12 
13 // a helper class for debug and error
14 // messages
15 class parallelId {};
16 
17 // print the callers rank and thread id
18 // to the given stream
19 SENSEI_EXPORT
20 std::ostream &operator<<(std::ostream &os, const parallelId &id);
21 
22 SENSEI_EXPORT int ioEnabled(int active_rank);
23 }
24 
25 #define ANSI_RED "\033[1;31m"
26 #define ANSI_GREEN "\033[1;32m"
27 #define ANSI_YELLOW "\033[1;33m"
28 #define ANSI_WHITE "\033[1;37m"
29 #define ANSI_OFF "\033[0m"
30 
31 #define BEGIN_HL(Color) (sensei::haveTty()?Color:"")
32 #define END_HL (sensei::haveTty()?ANSI_OFF:"")
33 
34 #define SENSEI_MESSAGE(Rank, Head, HeadColor, Msg) \
35 if (sensei::ioEnabled(Rank)) \
36 { \
37  std::cerr << BEGIN_HL(HeadColor) << Head << END_HL << " [" \
38  << sensei::parallelId() << "][" << __FILE__ << ":" << __LINE__ \
39  << "][" SENSEI_VERSION "]" << std::endl << BEGIN_HL(HeadColor) << Head \
40  << END_HL << " " << BEGIN_HL(ANSI_WHITE) << "" Msg << END_HL << std::endl; \
41 }
42 
43 #define SENSEI_ERROR(Msg) SENSEI_MESSAGE(-1, "ERROR:", ANSI_RED, Msg)
44 #define SENSEI_WARNING(Msg) SENSEI_MESSAGE(0, "WARNING:", ANSI_YELLOW, Msg)
45 #define SENSEI_STATUS(Msg) SENSEI_MESSAGE(0, "STATUS:", ANSI_GREEN, Msg)
46 #define SENSEI_STATUS_ALL(Msg) SENSEI_MESSAGE(-1, "STATUS:", ANSI_GREEN, Msg)
47 
48 #endif
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
Definition: Error.h:15