From 9bcb822963fc96c94dbe7dcc4134dcd2dac454ff Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 7 Jul 2016 16:06:01 +0200 Subject: Prepared sinksh trace --- common/log.cpp | 6 +++ common/log.h | 2 + common/test.cpp | 1 + sinksh/CMakeLists.txt | 1 + sinksh/sinksh_utils.cpp | 14 ++++--- sinksh/sinksh_utils.h | 1 + sinksh/syntax_modules/sink_trace.cpp | 72 ++++++++++++++++++++++++++++++++++++ synchronizer/main.cpp | 1 + 8 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 sinksh/syntax_modules/sink_trace.cpp diff --git a/common/log.cpp b/common/log.cpp index b0f6237..83cdc8a 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -16,6 +16,12 @@ static QSharedPointer config() return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/log.ini", QSettings::IniFormat); } +static QByteArray sPrimaryComponent; +void Sink::Log::setPrimaryComponent(const QString &component) +{ + sPrimaryComponent = component.toUtf8(); +} + class DebugStream : public QIODevice { public: diff --git a/common/log.h b/common/log.h index 0e92ea9..36b8efe 100644 --- a/common/log.h +++ b/common/log.h @@ -14,6 +14,8 @@ enum DebugLevel Error }; +void SINK_EXPORT setPrimaryComponent(const QString &component); + QByteArray SINK_EXPORT debugLevelName(DebugLevel debugLevel); DebugLevel SINK_EXPORT debugLevelFromName(const QByteArray &name); diff --git a/common/test.cpp b/common/test.cpp index 59ad9ec..c7d84cc 100644 --- a/common/test.cpp +++ b/common/test.cpp @@ -45,6 +45,7 @@ void Sink::Test::initTest() QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).removeRecursively(); // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); + Log::setPrimaryComponent("test"); } void Sink::Test::setTestModeEnabled(bool enabled) diff --git a/sinksh/CMakeLists.txt b/sinksh/CMakeLists.txt index e7d3b6e..f0e2f6c 100644 --- a/sinksh/CMakeLists.txt +++ b/sinksh/CMakeLists.txt @@ -15,6 +15,7 @@ set(sink_cli_SRCS syntax_modules/sink_stat.cpp syntax_modules/sink_sync.cpp syntax_modules/sink_show.cpp + syntax_modules/sink_trace.cpp sinksh_utils.cpp repl/repl.cpp repl/replStates.cpp diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 091eb38..2a6f628 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -113,6 +113,14 @@ QStringList resourceIds(State &state) return resources; } +QStringList debugareaCompleter(const QStringList &, const QString &fragment, State &state) +{ + QStringList list; + list << "foo.bar" << "tar.war" << "bluub"; + // return Utils::filteredCompletions(debugAreas(state), fragment); + return Utils::filteredCompletions(list, fragment); +} + QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) { return Utils::filteredCompletions(resourceIds(state), fragment); @@ -120,11 +128,7 @@ QStringList resourceCompleter(const QStringList &, const QString &fragment, Stat QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) { - static QStringList types = QStringList() << "resource" - << "folder" - << "mail" - << "event" - << "account"; + static QStringList types = s_types; if (commands.count() == 1) { return Utils::filteredCompletions(s_types, fragment); } diff --git a/sinksh/sinksh_utils.h b/sinksh/sinksh_utils.h index b5b6f3c..0a47661 100644 --- a/sinksh/sinksh_utils.h +++ b/sinksh/sinksh_utils.h @@ -40,6 +40,7 @@ QStringList resourceIds(); QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state); +QStringList debugareaCompleter(const QStringList &, const QString &fragment, State &state); QMap keyValueMapFromArgs(const QStringList &args); /** diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp new file mode 100644 index 0000000..e7b92de --- /dev/null +++ b/sinksh/syntax_modules/sink_trace.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 Christian Mollekopf + * + * 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 2 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, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include // tr() +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkTrace +{ + +bool trace(const QStringList &args, State &state) +{ + // if (args.isEmpty()) { + // state.printError(QObject::tr("Specifiy a debug area to trace.")); + // return false; + // } + // + // + qDebug() << "Trace arguments: " << args; + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + // Sink::Log::setDebugOutputFilter(Sink::Log::FilterType::Area, "filter"); + + return true; +} + +bool traceOff(const QStringList &args, State &state) +{ + Sink::Log::setDebugOutputLevel(Sink::Log::Log); + qDebug() << "Turned trace off: " << args; + return true; +} + +Syntax::List syntax() +{ + Syntax trace("trace", QObject::tr("Control trace debug output."), &SinkTrace::trace, Syntax::NotInteractive); + trace.completer = &SinkshUtils::debugareaCompleter; + + trace.children << Syntax("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive); + + return Syntax::List() << trace; +} + +REGISTER_SYNTAX(SinkTrace) + +} diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index 3168bfc..b3decf6 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp @@ -162,6 +162,7 @@ int main(int argc, char *argv[]) const QByteArray instanceIdentifier = arguments.at(1); const QByteArray resourceType = arguments.at(2); app.setApplicationName(instanceIdentifier); + Sink::Log::setPrimaryComponent(instanceIdentifier); Log() << "Starting: " << instanceIdentifier; QLockFile lockfile(instanceIdentifier + ".lock"); -- cgit v1.2.3