History

Add checkbox for showing extra source logs.

Kalila L committed 6 years ago

Commit 4096d751 parent ee43cfd4 files · +62 −32Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+37−30
@@ -40,6 +40,7 @@ · 39 unmodified lines
4040
4141 #include <shared/LocalFileAccessGate.h>
4242 #include <shared/QtHelpers.h>
43+#include <shared/AbstractLoggerInterface.h>
4344 #include <AudioConstants.h>
4445 #include <AudioEffectOptions.h>
4546 #include <AvatarData.h>
@@ -78,7 +79,6 @@ · 32 unmodified lines
7879 #include "StackTestScriptingInterface.h"
7980 #include "ModelScriptingInterface.h"
8081
81−
8282 #include <Profile.h>
8383
8484 #include "../../midi/src/Midi.h" // FIXME why won't a simpler include work?
@@ -127,38 +127,45 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { · 42 unmodified lines
127127
128128 // This message was sent by one of our script engines, let's try to see if we can find the source.
129129 // Note that the first entry in the backtrace should be "print" and is somewhat useless to us
130− QScriptContext* userContext = context;
131− while (userContext != nullptr && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) {
132− userContext = userContext->parentContext();
133− }
134− QString location;
135− if (userContext != nullptr) {
136− QScriptContextInfo contextInfo(userContext);
137− QString fileName = contextInfo.fileName();
138− int lineNumber = contextInfo.lineNumber();
139− QString functionName = contextInfo.functionName();
140−
141− location = functionName;
142− if (lineNumber != -1) {
143− location = QString("%1:%2").arg(location).arg(lineNumber);
144− }
145− if (!fileName.isEmpty()) {
146− if (location.isEmpty()) {
147− location = fileName;
148− } else {
149− location = QString("%1 at %2").arg(location).arg(fileName);
130+ AbstractLoggerInterface* loggerInterface = AbstractLoggerInterface::get();
131+ if (loggerInterface->showSourceDebugging()) {
132+ QScriptContext* userContext = context;
133+ while (userContext != nullptr && QScriptContextInfo(userContext).functionType() == QScriptContextInfo::NativeFunction) {
134+ userContext = userContext->parentContext();
135+ }
136+ QString location;
137+ if (userContext != nullptr) {
138+ QScriptContextInfo contextInfo(userContext);
139+ QString fileName = contextInfo.fileName();
140+ int lineNumber = contextInfo.lineNumber();
141+ QString functionName = contextInfo.functionName();
142+
143+ location = functionName;
144+ if (lineNumber != -1) {
145+ location = QString("%1:%2").arg(location).arg(lineNumber);
146+ }
147+ if (!fileName.isEmpty()) {
148+ if (location.isEmpty()) {
149+ location = fileName;
150+ } else {
151+ location = QString("%1 at %2").arg(location).arg(fileName);
152+ }
150153 }
151154 }
155+ if (location.isEmpty()) {
156+ location = scriptEngine->getFilename();
157+ }
158+
159+ // give the script engine a chance to notify the system about this message
160+ scriptEngine->print(message);
161+
162+ // send the message to debug log
163+ qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(location), qUtf8Printable(message));
164+ } else {
165+ scriptEngine->print(message);
166+ // prefix the script engine name to help disambiguate messages in the main debug log
167+ qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(scriptEngine->getFilename()), qUtf8Printable(message));
152168 }
153− if (location.isEmpty()) {
154− location = scriptEngine->getFilename();
155− }
156−
157− // give the script engine a chance to notify the system about this message
158− scriptEngine->print(message);
159−
160− // send the message to debug log
161− qCDebug(scriptengine_script, "[%s] %s", qUtf8Printable(location), qUtf8Printable(message));
162169
163170 return QScriptValue();
164171 }