ROSE 0.11.145.192
Diagnostics.h
1// Stuff related to ROSE diagnostics
2#ifndef ROSE_Diagnostics_H
3#define ROSE_Diagnostics_H
4#include <RoseFirst.h>
5
6#include "Sawyer/Assert.h"
7#include "Sawyer/Message.h"
8
9#include <rosedll.h>
10
11// How failed assertions behave
12#define ROSE_ASSERTION_ABORT 1 // call abort()
13#define ROSE_ASSERTION_EXIT 2 // call exit(1)
14#define ROSE_ASSERTION_THROW 3 // throw Rose::Diagnostics::FailedAssertion
15
16namespace Rose {
17
300namespace Diagnostics {
301
302// Make Sawyer message importance levels available here. That way, we don't have to "use namespace Sawyer::Message", which
303// also sucks in a lot of other stuff.
304using Sawyer::Message::DEBUG; // very low-level debugging mostly for developers
305using Sawyer::Message::TRACE; // more low-level debugging but maybe more interesting to users
306using Sawyer::Message::WHERE; // higher-level debugging to help users understand ROSE flow
307using Sawyer::Message::MARCH; // progress bars and other high-frequency messages
308using Sawyer::Message::INFO; // useful information about normal behavior such as stats
309using Sawyer::Message::WARN; // warnings that users should almost certainly see at least once
310using Sawyer::Message::ERROR; // recoverable errors, possibly followed by throw
311using Sawyer::Message::FATAL; // errors which are immediately followed by exit, abort, or similar
312
320
324ROSE_DLL_API extern Sawyer::Message::PrefixPtr mprefix;
325
327ROSE_DLL_API extern Sawyer::Message::Facility mlog;
328
332
335ROSE_DLL_API void initialize();
336
338ROSE_DLL_API bool isInitialized();
339
346ROSE_DLL_API void initAndRegister(Facility *mlog, const std::string &name);
347
355ROSE_DLL_API void deregister(Facility *mlog);
356
364 std::ostream &stream;
365public:
366 StreamPrintf(std::ostream &stream): stream(stream) {}
367#ifdef _MSC_VER
368 int operator()(const char *fmt, ...);
369#else
370 int operator()(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
371#endif
372};
373
391StreamPrintf mfprintf(std::ostream &stream);
392
393// See mfprintf. "mlog" must be resolved at point where macro is expanded.
394#define mprintf Rose::Diagnostics::mfprintf(mlog[Rose::Diagnostics::DEBUG])
395
396} // namespace
397} // namespace
398
399#endif
400
Intermediate class for printing to C++ ostreams with a printf-like API.
Collection of streams.
Definition Message.h:1606
Converts text to messages.
Definition Message.h:1396
Reference-counting intrusive smart pointer.
ROSE_DLL_API Sawyer::Message::DestinationPtr destination
< Collection of related streams, e.g., 'mlog'.
ROSE_DLL_API void deregister(Facility *mlog)
Deregister a facility.
ROSE_DLL_API void initAndRegister(Facility *mlog, const std::string &name)
Initialize and register a logging facility.
StreamPrintf mfprintf(std::ostream &stream)
Print to a C++ stream using a printf-like API.
ROSE_DLL_API Sawyer::Message::PrefixPtr mprefix
Default line prefix for message sinks created in ROSE.
ROSE_DLL_API bool isInitialized()
Returns true if diagnostics-related global variables have been initialized.
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
Definition sageBuilder.C:58
ROSE_DLL_API void initialize()
Initialize diagnostics-related global variables.
The ROSE library.
Facilities mfacilities
Library-provided facility group.
@ WARN
Warning messages that indicate an unusual situation from which the program was able to fully recover.
Definition Message.h:328
@ MARCH
Progress reports and other similar rapidly updating partial messages.
Definition Message.h:325
@ ERROR
Error messages that indicate an abnormal situation from which the program was able to at least partia...
Definition Message.h:330
@ TRACE
Detailed tracing information useful to end-users that are trying to understand program internals.
Definition Message.h:317
@ INFO
Informative messages.
Definition Message.h:326
@ FATAL
Messages that indicate an abnormal situation from which the program was unable to recover.
Definition Message.h:332
@ DEBUG
Messages intended to be useful primarily to the author of the code.
Definition Message.h:314
@ WHERE
Granular tracing information useful to end-users that are trying to understand program internals.
Definition Message.h:322