NuriaProject Framework
0.1
The NuriaProject Framework
|
Debugging and logging class of the Nuria Framework. More...
#include <debug.hpp>
Public Types | |
enum | Type { DebugMsg = 0, LogMsg = 1, WarnMsg = 2, ErrorMsg = 3, CriticalMsg = 4, AllLevels = CriticalMsg + 1, DefaultLowestMsgLevel = DebugMsg } |
Public Member Functions | |
Debug (Type type, const char *module, const char *fileName, int line, const char *className, const char *methodName) | |
~Debug () | |
Static Public Member Functions | |
static void | installMessageHandler () |
static void | installOutputHandler (const Callback &callback) |
static bool | isModuleDisabled (const char *module, Type level) |
static bool | isModuleDisabled (uint32_t module, Type level) |
static bool | isOutputDisabled () |
static void | qtMessageHandler (QtMsgType type, const QMessageLogContext &context, const QString &message) |
static void | setDestination (FILE *handle) |
static void | setDestination (QIODevice *device) |
static void | setModuleLevel (const char *module, Type leastLevel) |
static void | setOutputDisabled (bool disabled) |
static void | setOutputFormat (const char *format) |
static void | uninstallOutputHandler (const Callback &callback) |
Debugging and logging class of the Nuria Framework.
This class provides an easy way for outputting useful logging messages. You can use this as a drop-in replacement for QDebug.
Defining NURIA_DEBUG_NO_{DEBUG,LOG,WARN,ERROR,CRITICAL} will disable the level at compile-time, causing the corresponding logging macro to create code the compiler can optimize out.
You can redirect it using setDestination(). Use installOutputHandler() to redirect logging data to a method of yours instead.
The module name of a translation unit can be set by #defining NURIA_MODULE. The value of it is expected to be a literal. The line containing the #define must appear before the line where debug.hpp is #include'd.
enum Nuria::Debug::Type |
Type enumeration.
Nuria::Debug::Debug | ( | Type | type, |
const char * | module, | ||
const char * | fileName, | ||
int | line, | ||
const char * | className, | ||
const char * | methodName | ||
) |
Constructor. You usually don't use this directly. Use nDebug, nWarn, nError, nCritical or nLog instead.
Nuria::Debug::~Debug | ( | ) |
Destructor. Writes the debug data to the output stream.
|
static |
Install the QDebug message handler.
|
static |
Installs an output handler. A output handler is called each time the logging interface is used. You can use this if you need more control over logging in your application, for example if a single output file isn't enough for you.
The prototype for the callback looks like this:
type | The type of this message |
typeName | A human-readable representation of type |
moduleName | The module name |
file | The file name (As generated by the FILE macro) |
line | The line number (As generated by the LINE macro) |
className | The name of the class that sent the message |
methodName | The method name which sent the message |
message | The message itself |
|
static |
Returns true
if module at level is disabled.
|
inlinestatic |
Fast access for logging macros.
|
static |
Returns true
if the default output is disabled (as in not used).
|
static |
Use this function in combination with qInstallMsgHandler to tunnel all QDebug data through Debug. This way legacy code which uses qDebug() etc. will still use the log paths you defined.
With Qt5 this message handler also supports output of file name, line numbers and method names in debug mode. These will not be available in release mode.
|
static |
Use this method to redirect the logging output to some other destination. By default stdout
is used.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Uses device for output.
|
static |
Sets the logging level of a certain module. leastLevel is non-inclusive, which means that passing LogMsg
will output for everything below that in module. To completely disable logging, pass AllLevels
.
Passing nullptr
for module acts as a wildcard, affecting all modules.
|
static |
Use this method to disable or enable the default output method. By default the default output method is enabled.
default
output which you can manipulate through setDestination. It does not disable your output handlers.
|
static |
Sets the format which is used to write a message into the output stream. If format is 0
the default format will be used.
A new-line character is automatically appended.
|
static |
Removes an output handler.