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 
58 class Debug final {
59 public:
60  // Types
61 
66  enum class DebugLevel_t {
67  Nothing = 0,
68  Fatal =
69  10,
70  Critical = 20,
71  Exception = 30,
72  Warning = 40,
73  Info = 50,
74  DebugMsg =
75  60,
76  All = 100,
77  };
78 
79  // General methods
80 
89 
98 
105 
112 
118  const FilePath& getLogFilepath() const;
119 
135  void print(DebugLevel_t level, const QString& msg, const char* file,
136  int line);
137 
138  // Static methods
139 
150  static Debug* instance() {
151  static Debug dbg;
152  return &dbg;
153  }
154 
155 private:
156  // make some methods inaccessible...
157  Debug();
158  Debug(const Debug& other);
159  ~Debug();
160  Debug& operator=(const Debug& rhs);
161 
169  static void messageHandler(QtMsgType type, const QMessageLogContext& context,
170  const QString& msg);
171 
172  // General Attributes
177  QTextStream* mStderrStream;
179  QFile* mLogFile;
180  QMutex mMutex;
181 };
182 
183 /*******************************************************************************
184  * End of File
185  ******************************************************************************/
186 
187 } // namespace librepcb
188 
189 #endif // LIBREPCB_DEBUG_H
QFile * mLogFile
NULL if file logging is disabled.
Definition: debug.h:179
fatal errors [qFatal()] –> this will quit the application!
The Exception class.
Definition: exceptions.h:87
QTextStream * mStderrStream
the stream to stderr
Definition: debug.h:177
Debug & operator=(const Debug &rhs)
DebugLevel_t mDebugLevelLogFile
the current debug level for the log file
Definition: debug.h:176
The Debug class provides some methods for debugging/logging.
Definition: debug.h:58
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:180
FilePath mLogFilepath
the filepath for the log file
Definition: debug.h:178
~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:127
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:174
static Debug * instance()
Get a pointer to the instance of the singleton Debug object.
Definition: debug.h:150
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:66
Debug()
Definition: debug.cpp:38