summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_trace.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh/syntax_modules/sink_trace.cpp')
-rw-r--r--sinksh/syntax_modules/sink_trace.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp
new file mode 100644
index 0000000..8bd52a0
--- /dev/null
+++ b/sinksh/syntax_modules/sink_trace.cpp
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <QDebug>
21#include <QObject> // tr()
22#include <QTimer>
23
24#include "common/resource.h"
25#include "common/storage.h"
26#include "common/resourceconfig.h"
27#include "common/log.h"
28#include "common/storage.h"
29#include "common/definitions.h"
30
31#include "sinksh_utils.h"
32#include "state.h"
33#include "syntaxtree.h"
34#include "iostream"
35
36namespace SinkTrace
37{
38
39bool traceOff(const QStringList &args, State &state)
40{
41 Sink::Log::setDebugOutputLevel(Sink::Log::Log);
42 std::cout << "Turned trace off." << std::endl;
43 return true;
44}
45
46bool traceOn(const QStringList &args, State &state)
47{
48 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
49 if (args.isEmpty() || (args.size() == 1 && args.first() == "*")) {
50 Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList());
51 std::cout << "Set trace filter to: *" << std::endl;
52 } else {
53 QByteArrayList filter;
54 for (const auto &arg : args) {
55 filter << arg.toLatin1();
56 }
57 Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter);
58 std::cout << "Set trace filter to: " << filter.join(", ").toStdString() << std::endl;
59 }
60 return true;
61}
62
63bool trace(const QStringList &args, State &state)
64{
65 return traceOn(args, state);
66}
67
68
69Syntax::List syntax()
70{
71 Syntax trace("trace", QObject::tr("Control trace debug output."), &SinkTrace::trace, Syntax::NotInteractive);
72 trace.completer = &SinkshUtils::debugareaCompleter;
73
74 Syntax traceOff("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive);
75 traceOff.completer = &SinkshUtils::debugareaCompleter;
76 trace.children << traceOff;
77
78 Syntax traceOn("on", QObject::tr("Turns on trace output."), &SinkTrace::traceOn, Syntax::NotInteractive);
79 traceOn.completer = &SinkshUtils::debugareaCompleter;
80 trace.children << traceOn;
81
82 return Syntax::List() << trace;
83}
84
85REGISTER_SYNTAX(SinkTrace)
86
87}