Fix initialisation of the global logging category variable

Just accessing the raw variable doesn't guarantee the order
of construction and may lead to crashes in certain constellations.
pull/370/head
Michael Zanetti 2020-12-14 23:03:55 +01:00
parent a11a219bbf
commit f1fa59c535
4 changed files with 10 additions and 6 deletions

View File

@ -601,7 +601,7 @@ QStringList NymeaCore::getAvailableLanguages()
QStringList NymeaCore::loggingFilters()
{
return s_nymeaLoggingCategories;
return nymeaLoggingCategories();
}
QStringList NymeaCore::loggingFiltersPlugins()

View File

@ -100,6 +100,9 @@
/*! IntegrationPlugin constructor. IntegrationPlugins will be instantiated by the system.
This should never be called manually by a plugin implementation.
*/
NYMEA_LOGGING_CATEGORY(dcIntegrations, "Integrations")
IntegrationPlugin::IntegrationPlugin(QObject *parent):
QObject(parent)
{

View File

@ -34,10 +34,12 @@
#include <QDateTime>
#include <QMutex>
QStringList s_nymeaLoggingCategories;
QStringList& nymeaLoggingCategories() {
static QStringList _nymeaLoggingCategories;
return _nymeaLoggingCategories;
}
// FIXME: Those should eventually disappear from here
NYMEA_LOGGING_CATEGORY(dcIntegrations, "Integrations");
NYMEA_LOGGING_CATEGORY(dcThing, "Thing")
NYMEA_LOGGING_CATEGORY(dcThingManager, "ThingManager")
NYMEA_LOGGING_CATEGORY(dcSystem, "System")

View File

@ -34,13 +34,12 @@
#include <QLoggingCategory>
#include <QDebug>
extern QStringList s_nymeaLoggingCategories;
QStringList& nymeaLoggingCategories();
#define NYMEA_LOGGING_CATEGORY(name, string) \
class NymeaLoggingCategory##name: public QLoggingCategory { \
public: \
NymeaLoggingCategory##name(): QLoggingCategory(string) { s_nymeaLoggingCategories.append(string); } \
NymeaLoggingCategory##name(): QLoggingCategory(string) { nymeaLoggingCategories().append(string); } \
}; \
static NymeaLoggingCategory##name s_##name; \
const QLoggingCategory &name() \