Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -40,6 +40,7 @@ · 39 unmodified lines | ||
| 40 | 40 | |
| 41 | 41 | #include <shared/LocalFileAccessGate.h> |
| 42 | 42 | #include <shared/QtHelpers.h> |
| 43 | +#include <shared/AbstractLoggerInterface.h> | |
| 43 | 44 | #include <AudioConstants.h> |
| 44 | 45 | #include <AudioEffectOptions.h> |
| 45 | 46 | #include <AvatarData.h> |
| @@ -78,7 +79,6 @@ · 32 unmodified lines | ||
| 78 | 79 | #include "StackTestScriptingInterface.h" |
| 79 | 80 | #include "ModelScriptingInterface.h" |
| 80 | 81 | |
| 81 | − | |
| 82 | 82 | #include <Profile.h> |
| 83 | 83 | |
| 84 | 84 | #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 | ||
| 127 | 127 | |
| 128 | 128 | // This message was sent by one of our script engines, let's try to see if we can find the source. |
| 129 | 129 | // 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 | + } | |
| 150 | 153 | } |
| 151 | 154 | } |
| 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)); | |
| 152 | 168 | } |
| 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)); | |
| 162 | 169 | |
| 163 | 170 | return QScriptValue(); |
| 164 | 171 | } |