diff options
-rw-r--r-- | common/log.cpp | 23 | ||||
-rw-r--r-- | common/log.h | 9 | ||||
-rw-r--r-- | 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) | |||
152 | qputenv("SINKDEBUGAREAS", filter.join(',')); | 152 | qputenv("SINKDEBUGAREAS", filter.join(',')); |
153 | } | 153 | } |
154 | 154 | ||
155 | void Sink::Log::setDebugOutput(const QByteArrayList &output) | ||
156 | { | ||
157 | qputenv("SINKDEBUGOUTPUT", output.join(',')); | ||
158 | } | ||
159 | |||
155 | static QByteArray getProgramName() | 160 | static QByteArray getProgramName() |
156 | { | 161 | { |
157 | if (QCoreApplication::instance()) { | 162 | if (QCoreApplication::instance()) { |
@@ -171,6 +176,16 @@ static bool containsItemStartingWith(const QByteArray &pattern, const QByteArray | |||
171 | return false; | 176 | return false; |
172 | } | 177 | } |
173 | 178 | ||
179 | static bool caseInsensitiveContains(const QByteArray &pattern, const QByteArrayList &list) | ||
180 | { | ||
181 | for (const auto &item : list) { | ||
182 | if (item.toLower() == pattern) { | ||
183 | return true; | ||
184 | } | ||
185 | } | ||
186 | return false; | ||
187 | } | ||
188 | |||
174 | QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) | 189 | QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) |
175 | { | 190 | { |
176 | static NullStream nullstream; | 191 | static NullStream nullstream; |
@@ -214,9 +229,11 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, | |||
214 | break; | 229 | break; |
215 | }; | 230 | }; |
216 | 231 | ||
217 | bool showLocation = false; | 232 | auto debugOutput = qgetenv("SINKDEBUGOUTPUT").split(','); |
218 | bool showFunction = false; | 233 | |
219 | bool showProgram = false; | 234 | bool showLocation = debugOutput.isEmpty() ? false : caseInsensitiveContains("location", debugOutput); |
235 | bool showFunction = debugOutput.isEmpty() ? false : caseInsensitiveContains("function", debugOutput); | ||
236 | bool showProgram = debugOutput.isEmpty() ? false : caseInsensitiveContains("application", debugOutput); | ||
220 | bool useColor = true; | 237 | bool useColor = true; |
221 | bool multiline = false; | 238 | bool multiline = false; |
222 | 239 | ||
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); | |||
34 | */ | 34 | */ |
35 | void SINKCOMMON_EXPORT setFilter(const QByteArrayList &filter); | 35 | void SINKCOMMON_EXPORT setFilter(const QByteArrayList &filter); |
36 | 36 | ||
37 | /** | ||
38 | * Set an application debug output. | ||
39 | * | ||
40 | * Currently supported are: | ||
41 | * * Name: Application name used for filter. | ||
42 | * * Function: The function name: | ||
43 | * * Location: The source code location. | ||
44 | */ | ||
45 | void SINKCOMMON_EXPORT setDebugOutput(const QByteArrayList &filter); | ||
37 | 46 | ||
38 | QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); | 47 | QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); |
39 | 48 | ||
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) | |||
196 | return true; | 196 | return true; |
197 | } | 197 | } |
198 | 198 | ||
199 | bool setLoggingOutput(const QStringList &commands, State &state) | ||
200 | { | ||
201 | QByteArrayList output; | ||
202 | for (const auto &c : commands) { | ||
203 | output << c.toLatin1(); | ||
204 | } | ||
205 | |||
206 | Sink::Log::setDebugOutput(output); | ||
207 | return true; | ||
208 | } | ||
209 | |||
199 | Syntax::List syntax() | 210 | Syntax::List syntax() |
200 | { | 211 | { |
201 | Syntax::List syntax; | 212 | Syntax::List syntax; |
@@ -225,6 +236,10 @@ Syntax::List syntax() | |||
225 | Syntax loggingFilter("loggingFilter", QObject::tr("Set logging filter."), &CoreSyntax::setLoggingFilter); | 236 | Syntax loggingFilter("loggingFilter", QObject::tr("Set logging filter."), &CoreSyntax::setLoggingFilter); |
226 | set.children << loggingFilter; | 237 | set.children << loggingFilter; |
227 | 238 | ||
239 | Syntax loggingOutput("loggingOutput", QObject::tr("Set logging output."), &CoreSyntax::setLoggingFilter); | ||
240 | loggingOutput.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "name" << "function" << "location" << "", fragment, Qt::CaseInsensitive); }; | ||
241 | set.children << loggingOutput; | ||
242 | |||
228 | syntax << set; | 243 | syntax << set; |
229 | 244 | ||
230 | Syntax get("get", QObject::tr("Gets settings for the session")); | 245 | Syntax get("get", QObject::tr("Gets settings for the session")); |