1 #ifndef MHO_Message_HH__
2 #define MHO_Message_HH__
22 #define STRING(str) STR(str)
24 #ifdef HOPS_ENABLE_DEV_TODO
25 #if defined(__clang__)
26 #define DO_PRAGMA(x) _Pragma(#x)
27 #define TODO_FIXME_MSG(x) DO_PRAGMA(message #x)
28 #elif defined(__GNUC__)
29 #define DO_PRAGMA(x) _Pragma(#x)
30 #define TODO_FIXME_MSG(x) DO_PRAGMA(message #x)
32 #error Unsupported compiler
35 #define TODO_FIXME_MSG(x)
49 namespace sn = selfname;
98 #define MSG_ALIGN_PAD 32
124 void Lock() { fMutex.lock(); };
137 void AddKey(
const std::string& key);
185 : fTerminalStream(&std::cout), fAllowedLevel(eStatus), fCurrentLevel(eInfo), fCurrentKeyIsAllowed(false),
186 fAcceptAllKeys(false), fWasLastLineNewLine(false)
191 virtual ~MHO_Message(){};
194 std::string GetCurrentPrefix(
const MHO_MessageLevel& level,
const std::string& key);
198 std::ostream* fTerminalStream;
199 std::set< std::string > fKeys;
203 bool fCurrentKeyIsAllowed;
205 std::stringstream fMessageStream;
207 static std::string fRed;
208 static std::string fYellow;
209 static std::string fOrange;
210 static std::string fBlue;
211 static std::string fGreen;
212 static std::string fCyan;
213 static std::string fWhite;
214 static std::string fColorSuffix;
216 bool fWasLastLineNewLine;
219 std::string fPadding;
226 fMessageStream << item;
235 #ifndef HOPS_EXTRA_VERBOSE_MSG
237 #define msg_fatal(xKEY, xCONTENT) \
240 MHO_Message::GetInstance().Lock(); \
241 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) << xCONTENT; \
242 MHO_Message::GetInstance().Unlock(); \
247 #define msg_error(xKEY, xCONTENT) \
250 MHO_Message::GetInstance().Lock(); \
251 MHO_Message::GetInstance().SendMessage(eError, xKEY) << xCONTENT; \
252 MHO_Message::GetInstance().Unlock(); \
257 #define msg_warn(xKEY, xCONTENT) \
260 MHO_Message::GetInstance().Lock(); \
261 MHO_Message::GetInstance().SendMessage(eWarning, xKEY) << xCONTENT; \
262 MHO_Message::GetInstance().Unlock(); \
267 #define msg_status(xKEY, xCONTENT) \
270 MHO_Message::GetInstance().Lock(); \
271 MHO_Message::GetInstance().SendMessage(eStatus, xKEY) << xCONTENT; \
272 MHO_Message::GetInstance().Unlock(); \
277 #define msg_info(xKEY, xCONTENT) \
280 MHO_Message::GetInstance().Lock(); \
281 MHO_Message::GetInstance().SendMessage(eInfo, xKEY) << xCONTENT; \
282 MHO_Message::GetInstance().Unlock(); \
287 #ifdef HOPS_ENABLE_DEBUG_MSG
290 #define msg_debug(xKEY, xCONTENT) \
293 MHO_Message::GetInstance().Lock(); \
294 MHO_Message::GetInstance().SendMessage(eDebug, xKEY) << xCONTENT; \
295 MHO_Message::GetInstance().Unlock(); \
300 #define msg_debug(xKEY, xCONTENT)
305 #define msg_fatal(xKEY, xCONTENT) \
308 MHO_Message::GetInstance().Lock(); \
309 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) \
310 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
311 MHO_Message::GetInstance().Unlock(); \
316 #define msg_error(xKEY, xCONTENT) \
319 MHO_Message::GetInstance().Lock(); \
320 MHO_Message::GetInstance().SendMessage(eError, xKEY) \
321 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
322 MHO_Message::GetInstance().Unlock(); \
327 #define msg_warn(xKEY, xCONTENT) \
330 MHO_Message::GetInstance().Lock(); \
331 MHO_Message::GetInstance().SendMessage(eWarning, xKEY) \
332 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
333 MHO_Message::GetInstance().Unlock(); \
338 #define msg_status(xKEY, xCONTENT) \
341 MHO_Message::GetInstance().Lock(); \
342 MHO_Message::GetInstance().SendMessage(eStatus, xKEY) \
343 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
344 MHO_Message::GetInstance().Unlock(); \
349 #define msg_info(xKEY, xCONTENT) \
352 MHO_Message::GetInstance().Lock(); \
353 MHO_Message::GetInstance().SendMessage(eInfo, xKEY) \
354 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
355 MHO_Message::GetInstance().Unlock(); \
360 #ifdef HOPS_ENABLE_DEBUG_MSG
363 #define msg_debug(xKEY, xCONTENT) \
366 MHO_Message::GetInstance().Lock(); \
367 MHO_Message::GetInstance().SendMessage(eDebug, xKEY) \
368 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
369 MHO_Message::GetInstance().Unlock(); \
374 #define msg_debug(xKEY, xCONTENT)
379 #ifdef HOPS_ENABLE_STEPWISE_CHECK
381 #define check_step_error(xVALUE, xKEY, xCONTENT) \
384 MHO_Message::GetInstance().SendMessage(eError, xKEY) << xCONTENT; \
386 #define check_step_fatal(xVALUE, xKEY, xCONTENT) \
389 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) << xCONTENT; \
390 HOPS_ASSERT_THROW(xVALUE); \
394 #define check_step_error(xVALUE, xKEY, xCONTENT)
395 #define check_step_fatal(xVALUE, xKEY, xCONTENT)
#define MSG_ALIGN_PAD
Definition: MHO_Message.hh:98
constexpr to strip path prefix from FILE macros
uses the singleton pattern (as we only have one terminal)
Definition: MHO_Message.hh:102
MHO_Message(MHO_Message const &)=delete
Deleted copy constructor (singleton).
MHO_Message & SendMessage(const MHO_MessageLevel &level, const std::string &key)
Begin a new message with a specific level and key.
Definition: MHO_Message.cc:45
void SetLegacyMessageLevel(int legacy_message_level)
Set the message level using a legacy integer interface.
Definition: MHO_Message.cc:189
MHO_Message & operator=(MHO_Message const &)=delete
Deleted copy assignment operator (singleton).
void AcceptAllKeys()
Allow all message keys (no category/library filtering).
Definition: MHO_Message.hh:130
void LimitToKeySet()
Restrict messages to a defined key set.
Definition: MHO_Message.hh:133
void RemoveAllKeys()
Remove all message keys (disables all filtering).
Definition: MHO_Message.cc:29
void SetMessageLevel(MHO_MessageLevel level)
Set the allowed message level threshold.
Definition: MHO_Message.hh:151
void RemoveKey(const std::string &key)
Remove a message key from the allowed key set.
Definition: MHO_Message.cc:20
MHO_Message(MHO_Message &&)=delete
Deleted move constructor (singleton).
MHO_Message & operator<<(const XStreamableItemType &item)
Stream an item into the current message.
Definition: MHO_Message.hh:222
void Flush()
Flush the current output stream buffer.
Definition: MHO_Message.cc:34
void Lock()
Lock the message handler for thread-safe operations.
Definition: MHO_Message.hh:124
void AddKey(const std::string &key)
Add a message key to the allowed key set.
Definition: MHO_Message.cc:15
void Unlock()
Unlock the message handler.
Definition: MHO_Message.hh:127
MHO_Message & operator=(MHO_Message &&)=delete
Deleted move assignment operator (singleton).
MHO_MessageLevel GetMessageLevel() const
Get the currently configured message level threshold.
Definition: MHO_Message.hh:159
static MHO_Message & GetInstance()
Access the singleton instance of the message handler.
Definition: MHO_Message.hh:117
Definition: MHO_AdhocFlagging.hh:18
MHO_MessageLevel
Definition: MHO_Message.hh:68
@ eStatusLevel
use to inform about unexpected state which may lead to errors
Definition: MHO_Message.hh:74
@ eDebugLevel
extra information to inform about configuration/state of program
Definition: MHO_Message.hh:76
@ eWarningLevel
use for non-fatal errors which may lead to unexpected behavior
Definition: MHO_Message.hh:73
@ eSpecialLevel
Definition: MHO_Message.hh:69
@ eErrorLevel
use for fatal errors (program termination imminent)
Definition: MHO_Message.hh:72
@ eInfoLevel
information about the current execution status of the program
Definition: MHO_Message.hh:75
@ eFatalErrorLevel
mute all messages entirely, including fatal ones
Definition: MHO_Message.hh:71
@ eSilentErrorLevel
special print level
Definition: MHO_Message.hh:70
Class MHO_MessageEndline.
Definition: MHO_Message.hh:61
Class MHO_MessageNewline.
Definition: MHO_Message.hh:55