libquentier  0.5.0
The library for rich desktop clients of Evernote service
QuentierLogger.h
1 /*
2  * Copyright 2016-2020 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 
25 #include <QDebug>
26 #include <QString>
27 
28 namespace quentier {
29 
30 enum class LogLevel
31 {
32  Trace,
33  Debug,
34  Info,
35  Warning,
36  Error
37 };
38 
39 QUENTIER_EXPORT QDebug & operator<<(QDebug & dbg, const LogLevel logLevel);
40 
41 void QUENTIER_EXPORT QuentierInitializeLogging();
42 
43 void QUENTIER_EXPORT QuentierAddLogEntry(
44  const QString & sourceFileName,
45  const int sourceFileLineNumber,
46  const QString & message,
47  const LogLevel logLevel);
48 
49 LogLevel QUENTIER_EXPORT QuentierMinLogLevel();
50 
51 void QUENTIER_EXPORT QuentierSetMinLogLevel(const LogLevel logLevel);
52 
53 void QUENTIER_EXPORT QuentierAddStdOutLogDestination();
54 
55 bool QUENTIER_EXPORT QuentierIsLogLevelActive(const LogLevel logLevel);
56 
57 QString QUENTIER_EXPORT QuentierLogFilesDirPath();
58 
59 void QUENTIER_EXPORT QuentierRestartLogging();
60 
61 } // namespace quentier
62 
63 #define __QNLOG_QDEBUG_HELPER() \
64  dbg.nospace(); \
65  dbg.noquote() \
66 // __QNLOG_QDEBUG_HELPER
67 
68 #define __QNLOG_BASE(message, level) \
69  if (quentier::QuentierIsLogLevelActive(quentier::LogLevel::level)) \
70  { \
71  QString msg; \
72  QDebug dbg(&msg); \
73  __QNLOG_QDEBUG_HELPER(); \
74  dbg << message; \
75  quentier::QuentierAddLogEntry( \
76  QStringLiteral(__FILE__), \
77  __LINE__, msg, \
78  quentier::LogLevel::level); \
79  } \
80 // __QNLOG_BASE
81 
82 #define QNTRACE(message) \
83  __QNLOG_BASE(message, Trace) \
84 // QNTRACE
85 
86 #define QNDEBUG(message) \
87  __QNLOG_BASE(message, Debug) \
88 // QNDEBUG
89 
90 #define QNINFO(message) \
91  __QNLOG_BASE(message, Info) \
92 // QNINFO
93 
94 #define QNWARNING(message) \
95  __QNLOG_BASE(message, Warning) \
96 // QNWARNING
97 
98 #define QNERROR(message) \
99  __QNLOG_BASE(message, Error) \
100 // QNERROR
101 
102 #define QUENTIER_SET_MIN_LOG_LEVEL(level) \
103  quentier::QuentierSetMinLogLevel(quentier::LogLevel::level) \
104 // QUENTIER_SET_MIN_LOG_LEVEL
105 
106 #define QUENTIER_INITIALIZE_LOGGING() \
107  quentier::QuentierInitializeLogging() \
108 // QUENTIER_INITIALIZE_LOGGING
109 
110 #define QUENTIER_ADD_STDOUT_LOG_DESTINATION() \
111  quentier::QuentierAddStdOutLogDestination() \
112 // QUENTIER_ADD_STDOUT_LOG_DESTINATION
113 
114 #define QNLOG_FILE_LINENUMBER_DELIMITER ":"
115 
116 #endif // LIB_QUENTIER_LOGGING_QUENTIER_LOGGER_H