From e1716e503d96d4c8331fb1dc2e701f2b6df240ec Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 5 Feb 2016 11:59:30 +0100 Subject: Logging cleanup --- common/log.cpp | 18 ++++++++++-------- common/log.h | 21 ++++++++++++++------- sinksh/syntax_modules/core_syntax.cpp | 14 +++++++------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/common/log.cpp b/common/log.cpp index ee28a3b..d2e5f47 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -142,17 +142,19 @@ Sink::Log::DebugLevel Sink::Log::debugOutputLevel() return debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); } -void Sink::Log::setFilter(const QByteArrayList &filter) +void Sink::Log::setDebugOutputFilter(FilterType type, const QByteArrayList &filter) { - qputenv("SINKDEBUGFILTER", filter.join(',')); -} - -void Sink::Log::setAreas(const QByteArrayList &filter) -{ - qputenv("SINKDEBUGAREAS", filter.join(',')); + switch (type) { + case ApplicationName: + qputenv("SINKDEBUGFILTER", filter.join(',')); + break; + case Area: + qputenv("SINKDEBUGAREAS", filter.join(',')); + break; + } } -void Sink::Log::setDebugOutput(const QByteArrayList &output) +void Sink::Log::setDebugOutputFields(const QByteArrayList &output) { qputenv("SINKDEBUGOUTPUT", output.join(',')); } diff --git a/common/log.h b/common/log.h index 8a6c295..92d6cdd 100644 --- a/common/log.h +++ b/common/log.h @@ -24,25 +24,32 @@ DebugLevel SINKCOMMON_EXPORT debugLevelFromName(const QByteArray &name); void SINKCOMMON_EXPORT setDebugOutputLevel(DebugLevel); DebugLevel SINKCOMMON_EXPORT debugOutputLevel(); -/// Set debug areas that should be logged -void SINKCOMMON_EXPORT setAreas(const QByteArrayList &areas); +enum FilterType { + Area, + ApplicationName +}; /** - * Set an application name filter. + * Sets a debug output filter. + * + * Everything that is not matching the filter is ignored. + * An empty filter matches everything. * - * Note: In case of resources the identifier is the application name. + * Note: In case of resources the application name is the identifier. */ -void SINKCOMMON_EXPORT setFilter(const QByteArrayList &filter); +void SINKCOMMON_EXPORT setDebugOutputFilter(FilterType, const QByteArrayList &filter); /** - * Set an application debug output. + * Set the debug output fields. * * Currently supported are: * * Name: Application name used for filter. * * Function: The function name: * * Location: The source code location. + * + * These are additional items to the default ones (level, area, message). */ -void SINKCOMMON_EXPORT setDebugOutput(const QByteArrayList &filter); +void SINKCOMMON_EXPORT setDebugOutputFields(const QByteArrayList &filter); QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); diff --git a/sinksh/syntax_modules/core_syntax.cpp b/sinksh/syntax_modules/core_syntax.cpp index cb036b4..e90d894 100644 --- a/sinksh/syntax_modules/core_syntax.cpp +++ b/sinksh/syntax_modules/core_syntax.cpp @@ -176,7 +176,7 @@ bool setLoggingAreas(const QStringList &commands, State &state) areas << c.toLatin1(); } - Sink::Log::setAreas(areas); + Sink::Log::setDebugOutputFilter(Sink::Log::Area, areas); return true; } @@ -192,18 +192,18 @@ bool setLoggingFilter(const QStringList &commands, State &state) filter << c.toLatin1(); } - Sink::Log::setFilter(filter); + Sink::Log::setDebugOutputFilter(Sink::Log::ApplicationName, filter); return true; } -bool setLoggingOutput(const QStringList &commands, State &state) +bool setLoggingFields(const QStringList &commands, State &state) { QByteArrayList output; for (const auto &c : commands) { output << c.toLatin1(); } - Sink::Log::setDebugOutput(output); + Sink::Log::setDebugOutputFields(output); return true; } @@ -236,9 +236,9 @@ Syntax::List syntax() Syntax loggingFilter("loggingFilter", QObject::tr("Set logging filter."), &CoreSyntax::setLoggingFilter); set.children << loggingFilter; - Syntax loggingOutput("loggingOutput", QObject::tr("Set logging output."), &CoreSyntax::setLoggingFilter); - loggingOutput.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "name" << "function" << "location" << "", fragment, Qt::CaseInsensitive); }; - set.children << loggingOutput; + Syntax loggingFields("loggingFields", QObject::tr("Set logging fields."), &CoreSyntax::setLoggingFields); + loggingFields.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "name" << "function" << "location" << "", fragment, Qt::CaseInsensitive); }; + set.children << loggingFields; syntax << set; -- cgit v1.2.3