Commit 2b52905b authored by Karel Slaný's avatar Karel Slaný

Using the newly added log device.

parent 234084f5
......@@ -131,7 +131,6 @@ SOURCES += \
src/isds/isds_conversion.cpp \
src/isds/isds_type_conversion.cpp \
src/locker.cpp \
src/log/log.cpp \
src/main.cpp \
src/messages.cpp \
src/models/accountmodel.cpp \
......@@ -239,7 +238,6 @@ HEADERS += \
src/isds/isds_conversion.h \
src/isds/isds_type_conversion.h \
src/locker.h \
src/log/log.h \
src/messages.h \
src/models/accountmodel.h \
src/models/databoxmodel.h \
......
......@@ -27,9 +27,9 @@
#include <QSqlRecord>
#include <QVariant>
#include "src/io/db_tables.h"
#include "src/datovka_shared/io/records_management_db.h"
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
#include "src/io/db_tables.h"
/*!
* @brief Delete all entries from table.
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -28,7 +28,7 @@
#include "src/datovka_shared/io/sqlite/db.h"
#include "src/datovka_shared/io/sqlite/table.h"
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
const QString SQLiteDb::memoryLocation(":memory:");
const QString SQLiteDb::dbDriverType("QSQLITE");
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,7 +22,7 @@
*/
#include "src/datovka_shared/io/sqlite/db_single.h"
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
SQLiteDbSingle::SQLiteDbSingle(const QString &connectionName,
bool allowRelocation)
......
......@@ -27,7 +27,7 @@
#include <QVariant>
#include "src/datovka_shared/io/sqlite/table.h"
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
SQLiteTbl::SQLiteTbl(const QString &name,
const QVector< QPair<QString, enum EntryType> > &attrs,
......
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -23,8 +23,8 @@
#include "src/datovka_shared/crypto/crypto_pin.h"
#include "src/datovka_shared/crypto/crypto_wrapped.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/settings/pin.h"
#include "src/log/log.h"
#define SETTINGS_SECURITY_GROUP "security"
......
......@@ -25,8 +25,8 @@
#include "src/datovka_shared/crypto/crypto_pwd.h"
#include "src/datovka_shared/crypto/crypto_wrapped.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/log/log.h"
/* Records management configuration entry names. */
namespace RMNames {
......
/*
* Copyright (C) 2014-2016 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/log/log.h"
int debugVerbosity = 2;
int logVerbosity = 0;
/* There is not currently any implementation of a logging device. */
/*
* Copyright (C) 2014-2016 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include <QtGlobal>
/* Default debugging verbosity. */
extern int debugVerbosity;
/* Default logging verbosity. */
extern int logVerbosity;
/*!
* @brief Logging macro used for internal purposes.
*
* @param[in] logVerbThresh Logging verbosity threshold.
* @param[in] logFunc Logging method.
* @param[in] format Format of the messages, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define _internalLogNL(logVerbThresh, logFunc, format, ...) \
if (logVerbosity > (logVerbThresh)) { \
(logFunc)(format " (%s:%d, %s())", \
__VA_ARGS__, __FILE__, __LINE__, __func__); \
} else { \
(logFunc)(format, __VA_ARGS__); \
}
/*!
* @brief A macro which logs a function name followed with given debugging
* information. The data are logged only when the global verbosity variable
* exceeds the given threshold. Automatic newline is added.
*
* @param[in] verbThresh Verbosity threshold.
* @param[in] format Format of the messages, follows printf syntax.
* @param[in] ... Variadic arguments.
*
* @note This macro works only if the DEBUG macro is defined. If no DEBUG macro
* is defined then it won't generate any code.
*/
#if DEBUG
#define logDebugNL(verbThresh, format, ...) \
do { \
if (debugVerbosity > (verbThresh)) { \
_internalLogNL(0, qDebug, format, __VA_ARGS__); \
} \
} while (0)
#else /* !DEBUG */
#define logDebugNL(verbThresh, format, ...) \
(void) 0
#endif /* DEBUG */
/*!
* @brief Logs the debugging information even if the threshold was not set.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logDebugLv0NL(format, ...) \
logDebugNL(-1, format, __VA_ARGS__)
/*!
* @brief Logs the debugging information only if the verbosity exceeds 0.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logDebugLv1NL(format, ...) \
logDebugNL(0, format, __VA_ARGS__)
/*!
* @brief Logs the debugging information only if the verbosity exceeds 1.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logDebugLv2NL(format, ...) \
logDebugNL(1, format, __VA_ARGS__)
/*!
* @brief Logs the debugging information only if the verbosity exceeds 2.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logDebugLv3NL(format, ...) \
logDebugNL(2, format, __VA_ARGS__)
/*!
* @brief Logs info message. Automatic newline is added.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logInfoNL(format, ...) \
_internalLogNL(0, qInfo, format, __VA_ARGS__)
/*!
* @brief Logs warning message. Automatic newline is added.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logWarningNL(format, ...) \
_internalLogNL(0, qWarning, format, __VA_ARGS__)
/*!
* @brief Logs error message. Automatic newline is added.
*
* @param[in] format Format of the message, follows printf syntax.
* @param[in] ... Variadic arguments.
*/
#define logErrorNL(format, ...) \
_internalLogNL(0, qCritical, format, __VA_ARGS__)
......@@ -30,6 +30,7 @@
#include <QSslConfiguration>
#include <QSslSocket>
#include <QTranslator>
#include <QtGlobal> /* qInstallMessageHandler() */
#include <QtQuick>
#include <QtSvg>
#include <QtXml>
......@@ -38,6 +39,7 @@
#include "src/crypto/trusted_certs.h"
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/localisation/localisation.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/datovka_shared/worker/pool.h"
#include "src/dialogues/qml_dialogue_helper.h"
......@@ -47,7 +49,6 @@
#include "src/global.h"
#include "src/io/filesystem.h"
#include "src/locker.h"
#include "src/log/log.h"
#include "src/net/isds_wrapper.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
......@@ -222,6 +223,32 @@ void registerQmlTypes(const char *uri, const char *location,
}
}
/*!
* @brief Allocates global log facility.
*/
static
int allocGlobLog(void)
{
GlobInstcs::logPtr = new (std::nothrow) LogDevice;
if (Q_UNLIKELY(Q_NULLPTR == GlobInstcs::logPtr)) {
return -1;
}
return 0;
}
/*!
* @brief Deallocates global log facility.
*/
static
void deallocGlobLog(void)
{
if (Q_NULLPTR != GlobInstcs::logPtr) {
delete GlobInstcs::logPtr;
GlobInstcs::logPtr = Q_NULLPTR;
}
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
......@@ -230,6 +257,27 @@ int main(int argc, char *argv[])
/* First thing to create is the application object. */
QApplication app(argc, argv);
if (0 != allocGlobLog()) {
/* Cannot continue without logging facility. */
return EXIT_FAILURE;
}
/* Log everything. */
GlobInstcs::logPtr->setLogLevelBits(LogDevice::LF_STDERR, LOGSRC_ANY,
LOG_UPTO(LOG_DEBUG));
/* Set application data, identification, etc. */
app.setOrganizationName(APP_ORG_NAME);
app.setOrganizationDomain(APP_ORG_DOMAIN);
app.setApplicationName(APP_NAME);
app.setApplicationVersion(VERSION);
qInstallMessageHandler(globalLogOutput);
GlobInstcs::logPtr->setDebugVerbosity(2);
GlobInstcs::logPtr->setLogVerbosity(0);
/*
* This object needs to be created in the same thread as the
* application.
......@@ -248,12 +296,6 @@ int main(int argc, char *argv[])
/* Initialise random number generator. */
qsrand(QDateTime::currentDateTimeUtc().toTime_t());
/* set application data, identification, etc. */
app.setOrganizationName(APP_ORG_NAME);
app.setOrganizationDomain(APP_ORG_DOMAIN);
app.setApplicationName(APP_NAME);
app.setApplicationVersion(VERSION);
QCommandLineParser parser;
if (0 != setupCmdLineParser(parser)) {
return EXIT_FAILURE;
......@@ -653,5 +695,7 @@ int main(int argc, char *argv[])
delete GlobInstcs::msgProcEmitterPtr; GlobInstcs::msgProcEmitterPtr = Q_NULLPTR;
}
deallocGlobLog();
return ret;
}
......@@ -28,12 +28,12 @@
#include "src/datovka_shared/isds/message_interface.h"
#include "src/datovka_shared/isds/type_conversion.h"
#include "src/datovka_shared/isds/types.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/utility/strings.h"
#include "src/datovka_shared/worker/pool.h"
#include "src/dialogues/dialogues.h"
#include "src/global.h"
#include "src/io/filesystem.h"
#include "src/log/log.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
#include "src/models/messagemodel.h"
......
......@@ -24,13 +24,13 @@
#include <QMessageBox>
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/records_management/json/service_info.h"
#include "src/datovka_shared/records_management/json/upload_file.h"
#include "src/datovka_shared/records_management/json/upload_hierarchy.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/datovka_shared/worker/pool.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/models/accountmodel.h"
#include "src/qml_interaction/image_provider.h"
#include "src/records_management/models/upload_hierarchy_list_model.h"
......
......@@ -26,10 +26,10 @@
#include <QDir>
#include "src/datovka_shared/localisation/localisation.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/global.h"
#include "src/io/filesystem.h"
#include "src/log/log.h"
#include "src/settings.h"
/* Name of Datovka configuration file */
......
......@@ -29,8 +29,8 @@
#include <QSqlQuery>
#include <QSqlRecord>
#include "src/datovka_shared/log/log.h"
#include "src/io/filesystem.h"
#include "src/log/log.h"
#include "src/sqlite/db_tables.h"
#include "src/sqlite/dbs.h"
#include "src/sqlite/zfo_db.h"
......
......@@ -23,7 +23,7 @@
#include <QThread>
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
#include "src/net/isds_const.h"
#include "src/worker/task_change_password.h"
#include "src/xml/xml_base.h"
......
......@@ -23,8 +23,8 @@
#include <QThread>
#include "src/datovka_shared/log/log.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/worker/emitter.h"
......
......@@ -23,8 +23,8 @@
#include <QThread>
#include "src/datovka_shared/log/log.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/worker/emitter.h"
......
......@@ -23,8 +23,8 @@
#include <QThread>
#include "src/datovka_shared/log/log.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/io/filesystem.h"
#include "src/messages.h"
#include "src/net/db_wrapper.h"
......
......@@ -23,9 +23,9 @@
#include <QThread>
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/worker/pool.h" /* List with whole messages. */
#include "src/global.h"
#include "src/log/log.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/worker/emitter.h"
......
......@@ -23,7 +23,7 @@
#include <QThread>
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
#include "src/net/isds_const.h"
#include "src/worker/task_find_databox.h"
#include "src/xml/xml_find_databox.h"
......
......@@ -23,7 +23,7 @@
#include <QThread>
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
#include "src/net/isds_const.h"
#include "src/worker/emitter.h"
#include "src/worker/task_find_databox_fulltext.h"
......
......@@ -25,8 +25,8 @@
#include <QFile>
#include <QThread>
#include "src/datovka_shared/log/log.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/sqlite/account_db.h"
......
......@@ -23,7 +23,7 @@
#include <QThread>
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
#include "src/net/isds_const.h"
#include "src/worker/task_keep_alive.h"
#include "src/xml/xml_login.h"
......
......@@ -28,11 +28,11 @@
#include <QThread>
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/log/log.h"
#include "src/datovka_shared/records_management/io/records_management_connection.h"
#include "src/datovka_shared/records_management/json/entry_error.h"
#include "src/datovka_shared/records_management/json/stored_files.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/worker/emitter.h"
#include "src/worker/task_records_management_stored_messages.h"
......
......@@ -24,8 +24,8 @@
#include <QThread>
#include "src/auxiliaries/attachment_helper.h"
#include "src/datovka_shared/log/log.h"
#include "src/global.h"
#include "src/log/log.h"
#include "src/net/db_wrapper.h"
#include "src/net/isds_const.h"
#include "src/worker/emitter.h"
......
......@@ -23,7 +23,7 @@
#include <QThread>
#include "src/log/log.h"
#include "src/datovka_shared/log/log.h"
#include "src/net/isds_const.h"
#include "src/worker/task_send_sms.h"
#include "src/xml/xml_base.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment