LibrePCB Developers Documentation
|
The Debug class provides some methods for debugging/logging. More...
#include <debug.h>
Public Types | |
enum class | DebugLevel_t |
Public Member Functions | |
Debug (const Debug &other)=delete | |
void | setDebugLevelStderr (DebugLevel_t level) |
Set the debug level for the stderr output. | |
void | setDebugLevelLogFile (DebugLevel_t level) |
Set the debug level for the log file. | |
DebugLevel_t | getDebugLevelStderr () const |
Get the current debug level for the stderr output. | |
DebugLevel_t | getDebugLevelLogFile () const |
Get the current debug level for the log file. | |
const FilePath & | getLogFilepath () const |
Get the filename of the log file (even if file logging is disabled) | |
void | print (DebugLevel_t level, const QString &msg, const char *file, int line) |
Print a message to stderr/logfile (with respect to the current debug level) | |
Debug & | operator= (const Debug &rhs)=delete |
Static Public Member Functions | |
static Debug * | instance () |
Get a pointer to the instance of the singleton Debug object. | |
Private Member Functions | |
Debug () | |
~Debug () | |
Static Private Member Functions | |
static void | messageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
The message handler for qDebug(), qWarning(), qCritical() and qFatal() | |
Private Attributes | |
DebugLevel_t | mDebugLevelStderr |
the current debug level for the stderr output | |
DebugLevel_t | mDebugLevelLogFile |
the current debug level for the log file | |
QTextStream * | mStderrStream |
the stream to stderr | |
FilePath | mLogFilepath |
the filepath for the log file | |
QFile * | mLogFile |
NULL if file logging is disabled. | |
QMutex | mMutex |
for thread safety | |
The Debug class provides some methods for debugging/logging.
There will be created a singleton object of this class with Debug::instance(). The singleton will be created at the first call to Debug::instance(). The constructor will register the method Debug::messageHandler() as the message handler function for Qt's debug functions qDebug(), qWarning(), qCritical() and qFatal(). You can use these functions in your source code, and the Debug class will handle these messages.
Additionally, all exceptions of the type Exception (from exceptions.h) or a subclass of it, will automatically print a debug message of type Debug::DebugLevel::Exception.
This class can write messages to the stderr output and to a log file. You can set separate debug levels for both. By default, logging to a file is disabled.
|
strong |
Enum for debug levels. Only messages of the current or a higher level are printed.
Enumerator | |
---|---|
Nothing | nothing |
Fatal | fatal errors [qFatal()] --> this will quit the application! |
Critical | errors [qCritical()] |
Exception | thrown exceptions of (sub)class Exception |
Warning | warnings [qWarning()] |
Info | info messages [qInfo()] |
DebugMsg | irrelevant debug messages (a lot of messages!) [qDebug()] |
All | all |
|
private |
|
private |
void setDebugLevelStderr | ( | DebugLevel_t | level | ) |
Set the debug level for the stderr output.
Only messages of the current or a higher level are printed.
level | A value from Debug::DebugLevel (inclusive Nothing and All) |
void setDebugLevelLogFile | ( | DebugLevel_t | level | ) |
Set the debug level for the log file.
Only messages of the current or a higher level are printed.
level | A value from Debug::DebugLevel (inclusive Nothing and All) |
Debug::DebugLevel_t getDebugLevelStderr | ( | ) | const |
Get the current debug level for the stderr output.
Debug::DebugLevel_t getDebugLevelLogFile | ( | ) | const |
Get the current debug level for the log file.
const FilePath & getLogFilepath | ( | ) | const |
Get the filename of the log file (even if file logging is disabled)
void print | ( | DebugLevel_t | level, |
const QString & | msg, | ||
const char * | file, | ||
int | line | ||
) |
Print a message to stderr/logfile (with respect to the current debug level)
level | The debug level of the message (DO NOT USE "Nothing" and "All"!) |
msg | The message |
file | The source file (use the macro FILE) |
line | The line number (use the macro LINE) |
|
inlinestatic |
Get a pointer to the instance of the singleton Debug object.
|
staticprivate |
The message handler for qDebug(), qWarning(), qCritical() and qFatal()
This method is registered as the message handler for Qt's debug functions. This is done by the function qInstallMessageHandler() in Debug::Debug().
|
private |
the current debug level for the stderr output
|
private |
the current debug level for the log file
|
private |
the stream to stderr
|
private |
the filepath for the log file
|
private |
NULL if file logging is disabled.
|
private |
for thread safety