libquentier 0.5.0
The library for rich desktop clients of Evernote service
Loading...
Searching...
No Matches
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
24#include <QDebug>
25#include <QRegularExpression>
26#include <QString>
27#include <QTextStream>
28
29namespace quentier {
30
35enum class LogLevel
36{
37 Trace,
38 Debug,
39 Info,
40 Warning,
41 Error
42};
43
44QUENTIER_EXPORT QDebug & operator<<(QDebug & dbg, const LogLevel logLevel);
45
46QUENTIER_EXPORT QTextStream & operator<<(
47 QTextStream & strm, const LogLevel logLevel);
48
56void QUENTIER_EXPORT QuentierInitializeLogging();
57
61void QUENTIER_EXPORT QuentierAddLogEntry(
62 const QString & sourceFileName, const int sourceFileLineNumber,
63 const QString & component, const QString & message,
64 const LogLevel logLevel);
65
71LogLevel QUENTIER_EXPORT QuentierMinLogLevel();
72
76void QUENTIER_EXPORT QuentierSetMinLogLevel(const LogLevel logLevel);
77
82void QUENTIER_EXPORT QuentierAddStdOutLogDestination();
83
88bool QUENTIER_EXPORT QuentierIsLogLevelActive(const LogLevel logLevel);
89
93QString QUENTIER_EXPORT QuentierLogFilesDirPath();
94
98void QUENTIER_EXPORT QuentierRestartLogging();
99
103QRegularExpression QUENTIER_EXPORT QuentierLogComponentFilter();
104
108void QUENTIER_EXPORT
109QuentierSetLogComponentFilter(const QRegularExpression & filter);
110
111} // namespace quentier
112
113#define __QNLOG_BASE(component, message, level) \
114 if (quentier::QuentierIsLogLevelActive(quentier::LogLevel::level)) { \
115 QString msg; \
116 QDebug dbg(&msg); \
117 dbg.nospace(); \
118 dbg.noquote(); \
119 dbg << message; \
120 quentier::QuentierAddLogEntry( \
121 QStringLiteral(__FILE__), __LINE__, QString::fromUtf8(component), \
122 msg, quentier::LogLevel::level); \
123 } \
124 // __QNLOG_BASE
125
126#define QNTRACE(component, message) \
127 __QNLOG_BASE(component, message, Trace) \
128 // QNTRACE
129
130#define QNDEBUG(component, message) \
131 __QNLOG_BASE(component, message, Debug) \
132 // QNDEBUG
133
134#define QNINFO(component, message) \
135 __QNLOG_BASE(component, message, Info) \
136 // QNINFO
137
138#define QNWARNING(component, message) \
139 __QNLOG_BASE(component, message, Warning) \
140 // QNWARNING
141
142#define QNERROR(component, message) \
143 __QNLOG_BASE(component, message, Error) \
144 // QNERROR
145
146#define QUENTIER_SET_MIN_LOG_LEVEL(level) \
147 quentier::QuentierSetMinLogLevel( \
148 quentier::LogLevel::level) // QUENTIER_SET_MIN_LOG_LEVEL
149
150#define QUENTIER_INITIALIZE_LOGGING() \
151 quentier::QuentierInitializeLogging() // QUENTIER_INITIALIZE_LOGGING
152
153#define QUENTIER_ADD_STDOUT_LOG_DESTINATION() \
154 quentier:: \
155 QuentierAddStdOutLogDestination() // QUENTIER_ADD_STDOUT_LOG_DESTINATION
156
157#define QNLOG_FILE_LINENUMBER_DELIMITER ":"
158
159#endif // LIB_QUENTIER_LOGGING_QUENTIER_LOGGER_H