LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Debug Class Referencefinal

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

#include <debug.h>

+ Collaboration diagram for Debug:

Public Types

enum  DebugLevel_t
 

Public Member Functions

void setDebugLevelStderr (DebugLevel_t level)
 Set the debug level for the stderr output. More...
 
void setDebugLevelLogFile (DebugLevel_t level)
 Set the debug level for the log file. More...
 
DebugLevel_t getDebugLevelStderr () const
 Get the current debug level for the stderr output. More...
 
DebugLevel_t getDebugLevelLogFile () const
 Get the current debug level for the log file. More...
 
const FilePathgetLogFilepath () const
 Get the filename of the log file (even if file logging is disabled) More...
 
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) More...
 

Static Public Member Functions

static Debuginstance ()
 Get a pointer to the instance of the singleton Debug object. More...
 

Private Member Functions

 Debug ()
 
 Debug (const Debug &other)
 
 ~Debug ()
 
Debugoperator= (const Debug &rhs)
 

Static Private Member Functions

static void messageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg)
 The message handler for qDebug(), qWarning(), qCritical() and qFatal() More...
 

Private Attributes

DebugLevel_t mDebugLevelStderr
 the current debug level for the stderr output More...
 
DebugLevel_t mDebugLevelLogFile
 the current debug level for the log file More...
 
QTextStream * mStderrStream
 the stream to stderr More...
 
FilePath mLogFilepath
 the filepath for the log file More...
 
QFile * mLogFile
 NULL if file logging is disabled. More...
 
QMutex mMutex
 for thread safety More...
 

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 seperate debug levels for both. By default, logging to a file is disabled.

Author
ubruhin
Date
2014-07-28

Member Enumeration Documentation

enum 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 

throwed 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 ( )
private

+ Here is the call graph for this function:

Debug ( const Debug other)
private
~Debug ( )
private

Member Function Documentation

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:

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:

Debug::DebugLevel_t getDebugLevelStderr ( ) const

Get the current debug level for the stderr output.

Returns
The current debug level
Debug::DebugLevel_t getDebugLevelLogFile ( ) const

Get the current debug level for the log file.

Returns
The current debug level
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)
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 funtions 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:

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:

Debug& operator= ( const Debug rhs)
private
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

DebugLevel_t mDebugLevelStderr
private

the current debug level for the stderr output

DebugLevel_t mDebugLevelLogFile
private

the current debug level for the log file

QTextStream* mStderrStream
private

the stream to stderr

FilePath mLogFilepath
private

the filepath for the log file

QFile* mLogFile
private

NULL if file logging is disabled.

QMutex mMutex
private

for thread safety


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