File indexing completed on 2025-07-06 04:54:16
0001 /* 0002 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0018 */ 0019 0020 #include <QDebug> 0021 #include <QObject> // tr() 0022 #include <QTimer> 0023 0024 #include "common/resource.h" 0025 #include "common/storage.h" 0026 #include "common/resourceconfig.h" 0027 #include "common/log.h" 0028 #include "common/storage.h" 0029 #include "common/definitions.h" 0030 0031 #include "sinksh_utils.h" 0032 #include "state.h" 0033 #include "syntaxtree.h" 0034 #include "iostream" 0035 0036 namespace SinkTrace 0037 { 0038 0039 bool traceOff(const QStringList &args, State &state) 0040 { 0041 Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList()); 0042 Sink::Log::setDebugOutputLevel(Sink::Log::Log); 0043 std::cout << "Turned trace off." << std::endl; 0044 return true; 0045 } 0046 0047 bool traceOn(const QStringList &args, State &state) 0048 { 0049 Sink::Log::setDebugOutputLevel(Sink::Log::Trace); 0050 if (args.isEmpty() || (args.size() == 1 && args.first() == "*")) { 0051 Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList()); 0052 std::cout << "Set trace filter to: *" << std::endl; 0053 } else { 0054 QByteArrayList filter; 0055 for (const auto &arg : args) { 0056 filter << arg.toLatin1(); 0057 } 0058 Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); 0059 std::cout << "Set trace filter to: " << filter.join(", ").toStdString() << std::endl; 0060 } 0061 return true; 0062 } 0063 0064 bool trace(const QStringList &args, State &state) 0065 { 0066 return traceOn(args, state); 0067 } 0068 0069 Syntax::List syntax() 0070 { 0071 Syntax trace("trace", QObject::tr("Control trace debug output."), &SinkTrace::trace, Syntax::NotInteractive); 0072 trace.completer = &SinkshUtils::debugareaCompleter; 0073 0074 Syntax traceOff("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive); 0075 traceOff.completer = &SinkshUtils::debugareaCompleter; 0076 trace.children << traceOff; 0077 0078 Syntax traceOn("on", QObject::tr("Turns on trace output."), &SinkTrace::traceOn, Syntax::NotInteractive); 0079 traceOn.completer = &SinkshUtils::debugareaCompleter; 0080 trace.children << traceOn; 0081 0082 return Syntax::List() << trace; 0083 } 0084 0085 REGISTER_SYNTAX(SinkTrace) 0086 0087 }