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)
190 virtual ~MHO_Message(){};
193 std::string GetCurrentPrefix(
const MHO_MessageLevel& level,
const std::string& key);
197 std::ostream* fTerminalStream;
198 std::set< std::string > fKeys;
202 bool fCurrentKeyIsAllowed;
204 std::stringstream fMessageStream;
206 static std::string fRed;
207 static std::string fYellow;
208 static std::string fOrange;
209 static std::string fBlue;
210 static std::string fGreen;
211 static std::string fCyan;
212 static std::string fWhite;
213 static std::string fColorSuffix;
215 bool fWasLastLineNewLine;
218 std::string fPadding;
225 fMessageStream << item;
234 #ifndef HOPS_EXTRA_VERBOSE_MSG
236 #define msg_fatal(xKEY, xCONTENT) \
239 MHO_Message::GetInstance().Lock(); \
240 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) << xCONTENT; \
241 MHO_Message::GetInstance().Unlock(); \
246 #define msg_error(xKEY, xCONTENT) \
249 MHO_Message::GetInstance().Lock(); \
250 MHO_Message::GetInstance().SendMessage(eError, xKEY) << xCONTENT; \
251 MHO_Message::GetInstance().Unlock(); \
256 #define msg_warn(xKEY, xCONTENT) \
259 MHO_Message::GetInstance().Lock(); \
260 MHO_Message::GetInstance().SendMessage(eWarning, xKEY) << xCONTENT; \
261 MHO_Message::GetInstance().Unlock(); \
266 #define msg_status(xKEY, xCONTENT) \
269 MHO_Message::GetInstance().Lock(); \
270 MHO_Message::GetInstance().SendMessage(eStatus, xKEY) << xCONTENT; \
271 MHO_Message::GetInstance().Unlock(); \
276 #define msg_info(xKEY, xCONTENT) \
279 MHO_Message::GetInstance().Lock(); \
280 MHO_Message::GetInstance().SendMessage(eInfo, xKEY) << xCONTENT; \
281 MHO_Message::GetInstance().Unlock(); \
286 #ifdef HOPS_ENABLE_DEBUG_MSG
289 #define msg_debug(xKEY, xCONTENT) \
292 MHO_Message::GetInstance().Lock(); \
293 MHO_Message::GetInstance().SendMessage(eDebug, xKEY) << xCONTENT; \
294 MHO_Message::GetInstance().Unlock(); \
299 #define msg_debug(xKEY, xCONTENT)
304 #define msg_fatal(xKEY, xCONTENT) \
307 MHO_Message::GetInstance().Lock(); \
308 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) \
309 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
310 MHO_Message::GetInstance().Unlock(); \
315 #define msg_error(xKEY, xCONTENT) \
318 MHO_Message::GetInstance().Lock(); \
319 MHO_Message::GetInstance().SendMessage(eError, xKEY) \
320 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
321 MHO_Message::GetInstance().Unlock(); \
326 #define msg_warn(xKEY, xCONTENT) \
329 MHO_Message::GetInstance().Lock(); \
330 MHO_Message::GetInstance().SendMessage(eWarning, xKEY) \
331 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
332 MHO_Message::GetInstance().Unlock(); \
337 #define msg_status(xKEY, xCONTENT) \
340 MHO_Message::GetInstance().Lock(); \
341 MHO_Message::GetInstance().SendMessage(eStatus, xKEY) \
342 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
343 MHO_Message::GetInstance().Unlock(); \
348 #define msg_info(xKEY, xCONTENT) \
351 MHO_Message::GetInstance().Lock(); \
352 MHO_Message::GetInstance().SendMessage(eInfo, xKEY) \
353 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
354 MHO_Message::GetInstance().Unlock(); \
359 #ifdef HOPS_ENABLE_DEBUG_MSG
362 #define msg_debug(xKEY, xCONTENT) \
365 MHO_Message::GetInstance().Lock(); \
366 MHO_Message::GetInstance().SendMessage(eDebug, xKEY) \
367 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
368 MHO_Message::GetInstance().Unlock(); \
373 #define msg_debug(xKEY, xCONTENT)
378 #ifdef HOPS_ENABLE_STEPWISE_CHECK
380 #define check_step_error(xVALUE, xKEY, xCONTENT) \
383 MHO_Message::GetInstance().SendMessage(eError, xKEY) << xCONTENT; \
385 #define check_step_fatal(xVALUE, xKEY, xCONTENT) \
388 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) << xCONTENT; \
389 HOPS_ASSERT_THROW(xVALUE); \
393 #define check_step_error(xVALUE, xKEY, xCONTENT)
394 #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:221
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