From c8fbb5710737087b0cb5679d6211252dcba4ccce Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 5 Feb 2016 12:35:39 +0100 Subject: Use a config file instead of environment variables for log settings. qputenv only modifies the env of the current process, so akonadish didn't work at all to change the settings. We might have to do some performance optimizations at some point, but for the time being this works. --- common/log.cpp | 42 ++++++++++++++++++++++++++++++++---------- common/log.h | 2 ++ 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'common') diff --git a/common/log.cpp b/common/log.cpp index d2e5f47..4606e67 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -3,11 +3,19 @@ #include #include #include +#include +#include +#include #include #include using namespace Sink::Log; +static QSharedPointer config() +{ + return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/log.ini", QSettings::IniFormat); +} + class DebugStream: public QIODevice { public: @@ -134,29 +142,44 @@ DebugLevel Sink::Log::debugLevelFromName(const QByteArray &name) void Sink::Log::setDebugOutputLevel(DebugLevel debugLevel) { - qputenv("SINKDEBUGLEVEL", debugLevelName(debugLevel)); + config()->setValue("level", debugLevel); } Sink::Log::DebugLevel Sink::Log::debugOutputLevel() { - return debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); + return static_cast(config()->value("level", Sink::Log::Log).toInt()); } void Sink::Log::setDebugOutputFilter(FilterType type, const QByteArrayList &filter) { switch (type) { case ApplicationName: - qputenv("SINKDEBUGFILTER", filter.join(',')); + config()->setValue("applicationfilter", QVariant::fromValue(filter)); break; case Area: - qputenv("SINKDEBUGAREAS", filter.join(',')); + config()->setValue("areafilter", QVariant::fromValue(filter)); break; } } +QByteArrayList Sink::Log::debugOutputFilter(FilterType type) +{ + switch (type) { + case ApplicationName: + return config()->value("applicationfilter").value(); + case Area: + return config()->value("areafilter").value(); + } +} + void Sink::Log::setDebugOutputFields(const QByteArrayList &output) { - qputenv("SINKDEBUGOUTPUT", output.join(',')); + config()->setValue("outputfields", QVariant::fromValue(output)); +} + +QByteArrayList Sink::Log::debugOutputFields() +{ + return config()->value("outputfields").value(); } static QByteArray getProgramName() @@ -191,12 +214,11 @@ static bool caseInsensitiveContains(const QByteArray &pattern, const QByteArrayL QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) { static NullStream nullstream; - DebugLevel debugOutputLevel = debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); - if (debugLevel < debugOutputLevel) { + if (debugLevel < debugOutputLevel()) { return QDebug(&nullstream); } - auto areas = qgetenv("SINKDEBUGAREAS").split(','); + auto areas = debugOutputFilter(Sink::Log::Area); if (debugArea && !areas.isEmpty()) { if (!containsItemStartingWith(debugArea, areas)) { return QDebug(&nullstream); @@ -204,7 +226,7 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, } static QByteArray programName = getProgramName(); - auto filter = qgetenv("SINKDEBUGFILTER").split(','); + auto filter = debugOutputFilter(Sink::Log::ApplicationName); if (!filter.isEmpty() && !filter.contains(programName)) { if (!containsItemStartingWith(programName, filter)) { return QDebug(&nullstream); @@ -231,7 +253,7 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, break; }; - auto debugOutput = qgetenv("SINKDEBUGOUTPUT").split(','); + auto debugOutput = debugOutputFields(); bool showLocation = debugOutput.isEmpty() ? false : caseInsensitiveContains("location", debugOutput); bool showFunction = debugOutput.isEmpty() ? false : caseInsensitiveContains("function", debugOutput); diff --git a/common/log.h b/common/log.h index 92d6cdd..7d02634 100644 --- a/common/log.h +++ b/common/log.h @@ -38,6 +38,7 @@ enum FilterType { * Note: In case of resources the application name is the identifier. */ void SINKCOMMON_EXPORT setDebugOutputFilter(FilterType, const QByteArrayList &filter); +QByteArrayList SINKCOMMON_EXPORT debugOutputFilter(FilterType type); /** * Set the debug output fields. @@ -50,6 +51,7 @@ void SINKCOMMON_EXPORT setDebugOutputFilter(FilterType, const QByteArrayList &fi * These are additional items to the default ones (level, area, message). */ void SINKCOMMON_EXPORT setDebugOutputFields(const QByteArrayList &filter); +QByteArrayList SINKCOMMON_EXPORT debugOutputFields(); QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); -- cgit v1.2.3