LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
debug.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_DEBUG_H
21 #define LIBREPCB_DEBUG_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "fileio/filepath.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 /*******************************************************************************
36  * Class Debug
37  ******************************************************************************/
38 
61 class Debug final {
62 public:
63  // Types
64 
69  enum class DebugLevel_t {
70  Nothing = 0,
71  Fatal =
72  10,
73  Critical = 20,
74  Exception = 30,
75  Warning = 40,
76  Info = 50,
77  DebugMsg =
78  60,
79  All = 100,
80  };
81 
82  // General methods
83 
92 
101 
108 
115 
121  const FilePath& getLogFilepath() const;
122 
138  void print(DebugLevel_t level, const QString& msg, const char* file,
139  int line);
140 
141  // Static methods
142 
153  static Debug* instance() {
154  static Debug dbg;
155  return &dbg;
156  }
157 
158 private:
159  // make some methods inaccessible...
160  Debug();
161  Debug(const Debug& other);
162  ~Debug();
163  Debug& operator=(const Debug& rhs);
164 
172  static void messageHandler(QtMsgType type, const QMessageLogContext& context,
173  const QString& msg);
174 
175  // General Attributes
180  QTextStream* mStderrStream;
182  QFile* mLogFile;
183  QMutex mMutex;
184 };
185 
186 /*******************************************************************************
187  * End of File
188  ******************************************************************************/
189 
190 } // namespace librepcb
191 
192 #endif // LIBREPCB_DEBUG_H
QFile * mLogFile
NULL if file logging is disabled.
Definition: debug.h:182
fatal errors [qFatal()] –> this will quit the application!
The Exception class.
Definition: exceptions.h:87
QTextStream * mStderrStream
the stream to stderr
Definition: debug.h:180
Debug & operator=(const Debug &rhs)
DebugLevel_t mDebugLevelLogFile
the current debug level for the log file
Definition: debug.h:179
The Debug class provides some methods for debugging/logging.
Definition: debug.h:61
DebugLevel_t getDebugLevelStderr() const
Get the current debug level for the stderr output.
Definition: debug.cpp:105
QMutex mMutex
for thread safety
Definition: debug.h:183
FilePath mLogFilepath
the filepath for the log file
Definition: debug.h:181
~Debug()
Definition: debug.cpp:57
irrelevant debug messages (a lot of messages!) [qDebug()]
const FilePath & getLogFilepath() const
Get the filename of the log file (even if file logging is disabled)
Definition: debug.cpp:113
info messages [qInfo()]
DebugLevel_t getDebugLevelLogFile() const
Get the current debug level for the log file.
Definition: debug.cpp:109
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void setDebugLevelStderr(DebugLevel_t level)
Set the debug level for the stderr output.
Definition: debug.cpp:72
void setDebugLevelLogFile(DebugLevel_t level)
Set the debug level for the log file.
Definition: debug.cpp:76
DebugLevel_t mDebugLevelStderr
the current debug level for the stderr output
Definition: debug.h:177
static Debug * instance()
Get a pointer to the instance of the singleton Debug object.
Definition: debug.h:153
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
The message handler for qDebug(), qWarning(), qCritical() and qFatal()
Definition: debug.cpp:171
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)
Definition: debug.cpp:117
DebugLevel_t
Definition: debug.h:69
Debug()
Definition: debug.cpp:38