From e903e47cb0aada785e758264168d99bc4d0ad029 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 5 Feb 2016 11:38:45 +0100 Subject: Set debug output --- common/log.cpp | 23 ++++++++++++++++++++--- common/log.h | 9 +++++++++ sinksh/syntax_modules/core_syntax.cpp | 15 +++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/common/log.cpp b/common/log.cpp index 0f011b1..ee28a3b 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -152,6 +152,11 @@ void Sink::Log::setAreas(const QByteArrayList &filter) qputenv("SINKDEBUGAREAS", filter.join(',')); } +void Sink::Log::setDebugOutput(const QByteArrayList &output) +{ + qputenv("SINKDEBUGOUTPUT", output.join(',')); +} + static QByteArray getProgramName() { if (QCoreApplication::instance()) { @@ -171,6 +176,16 @@ static bool containsItemStartingWith(const QByteArray &pattern, const QByteArray return false; } +static bool caseInsensitiveContains(const QByteArray &pattern, const QByteArrayList &list) +{ + for (const auto &item : list) { + if (item.toLower() == pattern) { + return true; + } + } + return false; +} + QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) { static NullStream nullstream; @@ -214,9 +229,11 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, break; }; - bool showLocation = false; - bool showFunction = false; - bool showProgram = false; + auto debugOutput = qgetenv("SINKDEBUGOUTPUT").split(','); + + bool showLocation = debugOutput.isEmpty() ? false : caseInsensitiveContains("location", debugOutput); + bool showFunction = debugOutput.isEmpty() ? false : caseInsensitiveContains("function", debugOutput); + bool showProgram = debugOutput.isEmpty() ? false : caseInsensitiveContains("application", debugOutput); bool useColor = true; bool multiline = false; diff --git a/common/log.h b/common/log.h index c643f84..8a6c295 100644 --- a/common/log.h +++ b/common/log.h @@ -34,6 +34,15 @@ void SINKCOMMON_EXPORT setAreas(const QByteArrayList &areas); */ void SINKCOMMON_EXPORT setFilter(const QByteArrayList &filter); +/** + * Set an application debug output. + * + * Currently supported are: + * * Name: Application name used for filter. + * * Function: The function name: + * * Location: The source code location. + */ +void SINKCOMMON_EXPORT setDebugOutput(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 9325a7e..cb036b4 100644 --- a/sinksh/syntax_modules/core_syntax.cpp +++ b/sinksh/syntax_modules/core_syntax.cpp @@ -196,6 +196,17 @@ bool setLoggingFilter(const QStringList &commands, State &state) return true; } +bool setLoggingOutput(const QStringList &commands, State &state) +{ + QByteArrayList output; + for (const auto &c : commands) { + output << c.toLatin1(); + } + + Sink::Log::setDebugOutput(output); + return true; +} + Syntax::List syntax() { Syntax::List syntax; @@ -225,6 +236,10 @@ 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 << set; Syntax get("get", QObject::tr("Gets settings for the session")); -- cgit v1.2.3