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;
122 void Lock() { fMutex.lock(); };
135 void AddKey(
const std::string& key);
183 : fTerminalStream(&std::cout), fAllowedLevel(eStatus), fCurrentLevel(eInfo), fCurrentKeyIsAllowed(false),
184 fAcceptAllKeys(false), fWasLastLineNewLine(false){};
185 virtual ~MHO_Message(){};
188 std::string GetCurrentPrefix(
const MHO_MessageLevel& level,
const std::string& key);
192 std::ostream* fTerminalStream;
193 std::set< std::string > fKeys;
197 bool fCurrentKeyIsAllowed;
199 std::stringstream fMessageStream;
201 static std::string fRed;
202 static std::string fYellow;
203 static std::string fOrange;
204 static std::string fBlue;
205 static std::string fGreen;
206 static std::string fCyan;
207 static std::string fWhite;
208 static std::string fColorSuffix;
210 bool fWasLastLineNewLine;
217 fMessageStream << item;
226 #ifndef HOPS_EXTRA_VERBOSE_MSG
228 #define msg_fatal(xKEY, xCONTENT) \
231 MHO_Message::GetInstance().Lock(); \
232 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) << xCONTENT; \
233 MHO_Message::GetInstance().Unlock(); \
238 #define msg_error(xKEY, xCONTENT) \
241 MHO_Message::GetInstance().Lock(); \
242 MHO_Message::GetInstance().SendMessage(eError, xKEY) << xCONTENT; \
243 MHO_Message::GetInstance().Unlock(); \
248 #define msg_warn(xKEY, xCONTENT) \
251 MHO_Message::GetInstance().Lock(); \
252 MHO_Message::GetInstance().SendMessage(eWarning, xKEY) << xCONTENT; \
253 MHO_Message::GetInstance().Unlock(); \
258 #define msg_status(xKEY, xCONTENT) \
261 MHO_Message::GetInstance().Lock(); \
262 MHO_Message::GetInstance().SendMessage(eStatus, xKEY) << xCONTENT; \
263 MHO_Message::GetInstance().Unlock(); \
268 #define msg_info(xKEY, xCONTENT) \
271 MHO_Message::GetInstance().Lock(); \
272 MHO_Message::GetInstance().SendMessage(eInfo, xKEY) << xCONTENT; \
273 MHO_Message::GetInstance().Unlock(); \
278 #ifdef HOPS_ENABLE_DEBUG_MSG
281 #define msg_debug(xKEY, xCONTENT) \
284 MHO_Message::GetInstance().Lock(); \
285 MHO_Message::GetInstance().SendMessage(eDebug, xKEY) << xCONTENT; \
286 MHO_Message::GetInstance().Unlock(); \
291 #define msg_debug(xKEY, xCONTENT)
296 #define msg_fatal(xKEY, xCONTENT) \
299 MHO_Message::GetInstance().Lock(); \
300 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) \
301 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
302 MHO_Message::GetInstance().Unlock(); \
307 #define msg_error(xKEY, xCONTENT) \
310 MHO_Message::GetInstance().Lock(); \
311 MHO_Message::GetInstance().SendMessage(eError, xKEY) \
312 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
313 MHO_Message::GetInstance().Unlock(); \
318 #define msg_warn(xKEY, xCONTENT) \
321 MHO_Message::GetInstance().Lock(); \
322 MHO_Message::GetInstance().SendMessage(eWarning, xKEY) \
323 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
324 MHO_Message::GetInstance().Unlock(); \
329 #define msg_status(xKEY, xCONTENT) \
332 MHO_Message::GetInstance().Lock(); \
333 MHO_Message::GetInstance().SendMessage(eStatus, xKEY) \
334 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
335 MHO_Message::GetInstance().Unlock(); \
340 #define msg_info(xKEY, xCONTENT) \
343 MHO_Message::GetInstance().Lock(); \
344 MHO_Message::GetInstance().SendMessage(eInfo, xKEY) \
345 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
346 MHO_Message::GetInstance().Unlock(); \
351 #ifdef HOPS_ENABLE_DEBUG_MSG
354 #define msg_debug(xKEY, xCONTENT) \
357 MHO_Message::GetInstance().Lock(); \
358 MHO_Message::GetInstance().SendMessage(eDebug, xKEY) \
359 << "(" << sn::file_basename(__FILE__) << ":" << __LINE__ << ") " << xCONTENT; \
360 MHO_Message::GetInstance().Unlock(); \
365 #define msg_debug(xKEY, xCONTENT)
370 #ifdef HOPS_ENABLE_STEPWISE_CHECK
372 #define check_step_error(xVALUE, xKEY, xCONTENT) \
375 MHO_Message::GetInstance().SendMessage(eError, xKEY) << xCONTENT; \
377 #define check_step_fatal(xVALUE, xKEY, xCONTENT) \
380 MHO_Message::GetInstance().SendMessage(eFatal, xKEY) << xCONTENT; \
381 HOPS_ASSERT_THROW(xVALUE); \
385 #define check_step_error(xVALUE, xKEY, xCONTENT)
386 #define check_step_fatal(xVALUE, xKEY, xCONTENT)
constexpr to strip path prefix from FILE macros
uses the singleton pattern (as we only have one terminal)
Definition: MHO_Message.hh:100
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:48
void SetLegacyMessageLevel(int legacy_message_level)
Set the message level using a legacy integer interface.
Definition: MHO_Message.cc:195
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:128
void LimitToKeySet()
Restrict messages to a defined key set.
Definition: MHO_Message.hh:131
void RemoveAllKeys()
Remove all message keys (disables all filtering).
Definition: MHO_Message.cc:32
void SetMessageLevel(MHO_MessageLevel level)
Set the allowed message level threshold.
Definition: MHO_Message.hh:149
void RemoveKey(const std::string &key)
Remove a message key from the allowed key set.
Definition: MHO_Message.cc:23
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:213
void Flush()
Flush the current output stream buffer.
Definition: MHO_Message.cc:37
void Lock()
Lock the message handler for thread-safe operations.
Definition: MHO_Message.hh:122
void AddKey(const std::string &key)
Add a message key to the allowed key set.
Definition: MHO_Message.cc:18
void Unlock()
Unlock the message handler.
Definition: MHO_Message.hh:125
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:157
static MHO_Message & GetInstance()
Access the singleton instance of the message handler.
Definition: MHO_Message.hh:115
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