LibrePCB Developers Documentation
Loading...
Searching...
No Matches
Debug Class Referencefinal

The Debug class provides some methods for debugging/logging. More...

#include <debug.h>

+ Collaboration diagram for Debug:

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 FilePathgetLogFilepath () 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)
 
Debugoperator= (const Debug &rhs)=delete
 

Static Public Member Functions

static Debuginstance ()
 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
 

Detailed Description

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.

Member Enumeration Documentation

◆ DebugLevel_t

enum class DebugLevel_t
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

Constructor & Destructor Documentation

◆ Debug() [1/2]

Debug ( const Debug other)
delete

◆ Debug() [2/2]

Debug ( )
private
+ Here is the call graph for this function:

◆ ~Debug()

~Debug ( )
private

Member Function Documentation

◆ setDebugLevelStderr()

void setDebugLevelStderr ( DebugLevel_t  level)

Set the debug level for the stderr output.

Only messages of the current or a higher level are printed.

Parameters
levelA value from Debug::DebugLevel (inclusive Nothing and All)
+ Here is the caller graph for this function:

◆ setDebugLevelLogFile()

void setDebugLevelLogFile ( DebugLevel_t  level)

Set the debug level for the log file.

Only messages of the current or a higher level are printed.

Parameters
levelA value from Debug::DebugLevel (inclusive Nothing and All)
+ Here is the call graph for this function:

◆ getDebugLevelStderr()

Debug::DebugLevel_t getDebugLevelStderr ( ) const

Get the current debug level for the stderr output.

Returns
The current debug level

◆ getDebugLevelLogFile()

Debug::DebugLevel_t getDebugLevelLogFile ( ) const

Get the current debug level for the log file.

Returns
The current debug level

◆ getLogFilepath()

const FilePath & getLogFilepath ( ) const

Get the filename of the log file (even if file logging is disabled)

Returns
The filename of the log file (the file may do not exist)

◆ print()

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)

Note
You can use this method directly, but as the functions qDebug(), qWarning() (and so on) are more flexible and do not need the file and line arguments, it's easier to use the Qt's debug functions instead of this method.
Parameters
levelThe debug level of the message (DO NOT USE "Nothing" and "All"!)
msgThe message
fileThe source file (use the macro FILE)
lineThe line number (use the macro LINE)
+ Here is the caller graph for this function:

◆ instance()

static Debug * instance ( )
inlinestatic

Get a pointer to the instance of the singleton Debug object.

Warning
The singleton object will be created when calling this method the first time. You mustn't call this method before setting the application's organization and name, as this method will use these values to determine a filename for the log file!
Returns
A pointer to the singleton object
+ Here is the caller graph for this function:

◆ operator=()

Debug & operator= ( const Debug rhs)
delete

◆ messageHandler()

void messageHandler ( QtMsgType  type,
const QMessageLogContext &  context,
const QString &  msg 
)
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mDebugLevelStderr

DebugLevel_t mDebugLevelStderr
private

the current debug level for the stderr output

◆ mDebugLevelLogFile

DebugLevel_t mDebugLevelLogFile
private

the current debug level for the log file

◆ mStderrStream

QTextStream* mStderrStream
private

the stream to stderr

◆ mLogFilepath

FilePath mLogFilepath
private

the filepath for the log file

◆ mLogFile

QFile* mLogFile
private

NULL if file logging is disabled.

◆ mMutex

QMutex mMutex
private

for thread safety


The documentation for this class was generated from the following files: