ROSE  0.9.10.135
Diagnostics.h
1 // Stuff related to ROSE diagnostics
2 #ifndef ROSE_Diagnostics_H
3 #define ROSE_Diagnostics_H
4 
5 #include "Sawyer/Assert.h"
6 #include "Sawyer/Message.h"
7 
8 // How failed assertions behave
9 #define ROSE_ASSERTION_ABORT 1 // call abort()
10 #define ROSE_ASSERTION_EXIT 2 // call exit(1)
11 #define ROSE_ASSERTION_THROW 3 // throw Rose::Diagnostics::FailedAssertion
12 
13 namespace Rose {
14 
267 namespace Diagnostics {
268 
269 // Make Sawyer message importance levels available here. That way, we don't have to "use namespace Sawyer::Message", which
270 // also sucks in a lot of other stuff.
271 using Sawyer::Message::DEBUG; // very low-level debugging mostly for developers
272 using Sawyer::Message::TRACE; // more low-level debugging but maybe more interesting to users
273 using Sawyer::Message::WHERE; // higher-level debugging to help users understand ROSE flow
274 using Sawyer::Message::MARCH; // progress bars and other high-frequency messages
275 using Sawyer::Message::INFO; // useful information about normal behavior such as stats
276 using Sawyer::Message::WARN; // warnings that users should almost certainly see at least once
277 using Sawyer::Message::ERROR; // recoverable errors, possibly followed by throw
278 using Sawyer::Message::FATAL; // errors which are immediately followed by exit, abort, or similar
279 
280 using Sawyer::Message::Stream; // one message stream, e.g., 'mlog[INFO]'
281 using Sawyer::Message::Facility; // collection of related streams, e.g., 'mlog'
282 
286 ROSE_DLL_API extern Sawyer::Message::DestinationPtr destination;
287 
291 ROSE_DLL_API extern Sawyer::Message::PrefixPtr mprefix;
292 
294 ROSE_DLL_API extern Sawyer::Message::Facility mlog;
295 
299 
302 ROSE_DLL_API void initialize();
303 
305 ROSE_DLL_API bool isInitialized();
306 
313 void initAndRegister(Facility *mlog, const std::string &name);
314 
315 // [Robb P Matzke 2017-02-16]: deprecated: The version that takes a pointer first argument is a better design because it gives
316 // the user a better clue that we're saving a reference rather than a copy. Note: ROSE_DEPRECATED not defined here.
317 ROSE_DLL_API void initAndRegister(Facility &mlog, const std::string &name) SAWYER_DEPRECATED("use a pointer for the first argument");
318 
326 ROSE_DLL_API void deregister(Facility *mlog);
327 
335  std::ostream &stream;
336 public:
337  StreamPrintf(std::ostream &stream): stream(stream) {}
338 #ifdef _MSC_VER
339  int operator()(const char *fmt, ...);
340 #else
341  int operator()(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
342 #endif
343 };
344 
362 StreamPrintf mfprintf(std::ostream &stream);
363 
364 // See mfprintf. "mlog" must be resolved at point where macro is expanded.
365 #define mprintf Rose::Diagnostics::mfprintf(mlog[Rose::Diagnostics::DEBUG])
366 
367 } // namespace
368 } // namespace
369 
370 #endif
371 
Messages intended to be useful primarily to the author of the code.
Definition: Message.h:311
Collection of streams.
Definition: Message.h:1579
void initAndRegister(Facility *mlog, const std::string &name)
Initialize and register a logging facility.
ROSE_DLL_API void deregister(Facility *mlog)
Deregister a facility.
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Error messages that indicate an abnormal situation from which the program was able to at least partia...
Definition: Message.h:327
ROSE_DLL_API Sawyer::Message::PrefixPtr mprefix
Default line prefix for message sinks created in ROSE.
Main namespace for the ROSE library.
Messages that indicate an abnormal situation from which the program was unable to recover...
Definition: Message.h:329
Reference-counting smart pointer.
Definition: SharedPointer.h:34
ROSE_DLL_API void initialize()
Initialize diagnostics-related global variables.
Progress reports and other similar rapidly updating partial messages.
Definition: Message.h:322
Facilities mfacilities
Library-provided facility group.
ROSE_DLL_API bool isInitialized()
Returns true if diagnostics-related global variables have been initialized.
Warning messages that indicate an unusual situation from which the program was able to fully recover...
Definition: Message.h:325
Detailed tracing information useful to end-users that are trying to understand program internals...
Definition: Message.h:314
StreamPrintf mfprintf(std::ostream &stream)
Print to a C++ stream using a printf-like API.
Converts text to messages.
Definition: Message.h:1394
ROSE_DLL_API Sawyer::Message::DestinationPtr destination
Default destination for ROSE diagnostics.
Informative messages.
Definition: Message.h:323
Intermediate class for printing to C++ ostreams with a printf-like API.
Definition: Diagnostics.h:334
Granular tracing information useful to end-users that are trying to understand program internals...
Definition: Message.h:319