diff options
author | Aaron Seigo <aseigo@kde.org> | 2016-01-10 11:19:49 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2016-01-10 11:20:31 +0100 |
commit | b59a7fe545aa2732e98ecc373c4ab5ca741cd920 (patch) | |
tree | 52f729edad99ea4e8aecce1b8da00387216c0f6f /akonadish/syntax_modules/core_syntax.cpp | |
parent | b3275b0e40c40dd20839c885a8b02f631f8032d0 (diff) | |
download | sink-b59a7fe545aa2732e98ecc373c4ab5ca741cd920.tar.gz sink-b59a7fe545aa2732e98ecc373c4ab5ca741cd920.zip |
logging level setting
Diffstat (limited to 'akonadish/syntax_modules/core_syntax.cpp')
-rw-r--r-- | akonadish/syntax_modules/core_syntax.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index b4812df..ccf96c1 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "state.h" | 25 | #include "state.h" |
26 | #include "syntaxtree.h" | 26 | #include "syntaxtree.h" |
27 | #include "utils.h" | ||
27 | 28 | ||
28 | namespace CoreSyntax | 29 | namespace CoreSyntax |
29 | { | 30 | { |
@@ -145,6 +146,24 @@ bool printSyntaxTree(const QStringList &, State &state) | |||
145 | return true; | 146 | return true; |
146 | } | 147 | } |
147 | 148 | ||
149 | bool setLoggingLevel(const QStringList &commands, State &state) | ||
150 | { | ||
151 | if (commands.count() != 1) { | ||
152 | state.printError(QObject::tr("Wrong number of arguments; expected 1 got %1").arg(commands.count())); | ||
153 | return false; | ||
154 | } | ||
155 | |||
156 | state.setLoggingLevel(commands.at(0)); | ||
157 | return true; | ||
158 | } | ||
159 | |||
160 | bool printLoggingLevel(const QStringList &commands, State &state) | ||
161 | { | ||
162 | const QString level = state.loggingLevel(); | ||
163 | state.printLine(level); | ||
164 | return true; | ||
165 | } | ||
166 | |||
148 | Syntax::List syntax() | 167 | Syntax::List syntax() |
149 | { | 168 | { |
150 | Syntax::List syntax; | 169 | Syntax::List syntax; |
@@ -158,15 +177,22 @@ Syntax::List syntax() | |||
158 | 177 | ||
159 | Syntax set("set", QObject::tr("Sets settings for the session")); | 178 | Syntax set("set", QObject::tr("Sets settings for the session")); |
160 | set.children << Syntax("debug", QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); | 179 | set.children << Syntax("debug", QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); |
180 | |||
161 | Syntax setTiming = Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete")); | 181 | Syntax setTiming = Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete")); |
162 | setTiming.children << Syntax("on", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(true); return true; }); | 182 | setTiming.children << Syntax("on", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(true); return true; }); |
163 | setTiming.children << Syntax("off", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(false); return true; }); | 183 | setTiming.children << Syntax("off", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(false); return true; }); |
164 | set.children << setTiming; | 184 | set.children << setTiming; |
185 | |||
186 | Syntax logging("logging", QObject::tr("Set the logging level to one of Trace, Log, Warning or Error"), &CoreSyntax::setLoggingLevel); | ||
187 | logging.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "trace" << "log" << "warning" << "error", fragment, Qt::CaseInsensitive); }; | ||
188 | set.children << logging; | ||
189 | |||
165 | syntax << set; | 190 | syntax << set; |
166 | 191 | ||
167 | Syntax get("get", QObject::tr("Gets settings for the session")); | 192 | Syntax get("get", QObject::tr("Gets settings for the session")); |
168 | get.children << Syntax("debug", QObject::tr("The current debug level from 0 to 6"), &CoreSyntax::printDebugLevel); | 193 | get.children << Syntax("debug", QObject::tr("The current debug level from 0 to 6"), &CoreSyntax::printDebugLevel); |
169 | get.children << Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete"), &CoreSyntax::printCommandTiming); | 194 | get.children << Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete"), &CoreSyntax::printCommandTiming); |
195 | get.children << Syntax("logging", QObject::tr("The current logging level"), &CoreSyntax::printLoggingLevel); | ||
170 | syntax << get; | 196 | syntax << get; |
171 | 197 | ||
172 | return syntax; | 198 | return syntax; |