libquentier  0.4.0
The library for rich desktop clients of Evernote service
QuentierLogger.h
1 /*
2  * Copyright 2016 Dmitry Ivanov
3  *
4  * This file is part of libquentier
5  *
6  * libquentier is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * libquentier is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIB_QUENTIER_LOGGING_QUENTIER_LOGGER_H
20 #define LIB_QUENTIER_LOGGING_QUENTIER_LOGGER_H
21 
22 #include <quentier/utility/Linkage.h>
23 #include <quentier/utility/Macros.h>
24 #include <QString>
25 #include <QDebug>
26 
27 namespace quentier {
28 
29 class LogLevel
30 {
31 public:
32  enum type {
33  TraceLevel,
34  DebugLevel,
35  InfoLevel,
36  WarnLevel,
37  ErrorLevel
38  };
39 };
40 
41 void QUENTIER_EXPORT QuentierInitializeLogging();
42 
43 void QUENTIER_EXPORT QuentierAddLogEntry(const QString & sourceFileName, const int sourceFileLineNumber,
44  const QString & message, const LogLevel::type logLevel);
45 
46 LogLevel::type QUENTIER_EXPORT QuentierMinLogLevel();
47 
48 void QUENTIER_EXPORT QuentierSetMinLogLevel(const LogLevel::type logLevel);
49 
50 void QUENTIER_EXPORT QuentierAddStdOutLogDestination();
51 
52 bool QUENTIER_EXPORT QuentierIsLogLevelActive(const LogLevel::type logLevel);
53 
54 QString QUENTIER_EXPORT QuentierLogFilesDirPath();
55 
56 } // namespace quentier
57 
58 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
59 #define __QNLOG_QDEBUG_HELPER() \
60  dbg.nospace(); \
61  dbg.noquote()
62 #else
63 #define __QNLOG_QDEBUG_HELPER() \
64  dbg.nospace()
65 #endif
66 
67 #define __QNLOG_BASE(message, level) \
68  if (quentier::QuentierIsLogLevelActive(quentier::LogLevel::level##Level)) { \
69  QString msg; \
70  QDebug dbg(&msg); \
71  __QNLOG_QDEBUG_HELPER(); \
72  dbg << message; \
73  quentier::QuentierAddLogEntry(QStringLiteral(__FILE__), __LINE__, msg, quentier::LogLevel::level##Level); \
74  }
75 
76 #define QNTRACE(message) \
77  __QNLOG_BASE(message, Trace)
78 
79 #define QNDEBUG(message) \
80  __QNLOG_BASE(message, Debug)
81 
82 #define QNINFO(message) \
83  __QNLOG_BASE(message, Info)
84 
85 #define QNWARNING(message) \
86  __QNLOG_BASE(message, Warn)
87 
88 #define QNERROR(message) \
89  __QNLOG_BASE(message, Error)
90 
91 #define QUENTIER_SET_MIN_LOG_LEVEL(level) \
92  quentier::QuentierSetMinLogLevel(quentier::LogLevel::level##Level)
93 
94 #define QUENTIER_INITIALIZE_LOGGING() \
95  quentier::QuentierInitializeLogging()
96 
97 #define QUENTIER_ADD_STDOUT_LOG_DESTINATION() \
98  quentier::QuentierAddStdOutLogDestination()
99 
100 #endif // LIB_QUENTIER_LOGGING_QUENTIER_LOGGER_H
Definition: QuentierLogger.h:29