Use logging categories everywhere in the base scripting engine code

This commit is contained in:
Dale Glass 2023-03-07 00:13:22 +01:00 committed by ksuprynowicz
parent 0fc2ab870a
commit 4d8a20aed7
7 changed files with 25 additions and 23 deletions

View file

@ -153,12 +153,12 @@ ScriptValue scriptValueFromEnumClass(ScriptEngine* eng, const T& enumValue) {
template <class T> template <class T>
bool scriptValueToEnumClass(const ScriptValue& value, T& enumValue) { bool scriptValueToEnumClass(const ScriptValue& value, T& enumValue) {
if(!value.isNumber()){ if(!value.isNumber()){
qDebug() << "ScriptValue \"" << value.toQObject()->metaObject()->className() << "\" is not a number"; qCDebug(scriptengine) << "ScriptValue \"" << value.toQObject()->metaObject()->className() << "\" is not a number";
return false; return false;
} }
QMetaEnum metaEnum = QMetaEnum::fromType<T>(); QMetaEnum metaEnum = QMetaEnum::fromType<T>();
if (!metaEnum.isValid()) { if (!metaEnum.isValid()) {
qDebug() << "Invalid QMetaEnum"; qCDebug(scriptengine) << "Invalid QMetaEnum";
return false; return false;
} }
bool isValid = false; bool isValid = false;
@ -173,7 +173,7 @@ bool scriptValueToEnumClass(const ScriptValue& value, T& enumValue) {
enumValue = static_cast<T>(enumInteger); enumValue = static_cast<T>(enumInteger);
return true; return true;
} else { } else {
qDebug() << "ScriptValue has invalid value " << value.toInteger() << " for enum" << metaEnum.name(); qCDebug(scriptengine) << "ScriptValue has invalid value " << value.toInteger() << " for enum" << metaEnum.name();
return false; return false;
} }
} }

View file

@ -360,7 +360,7 @@ void ScriptEngines::loadScripts() {
void ScriptEngines::saveScripts() { void ScriptEngines::saveScripts() {
// Do not save anything if we are in the process of shutting down // Do not save anything if we are in the process of shutting down
if (qApp->closingDown()) { if (qApp->closingDown()) {
qWarning() << "Trying to save scripts during shutdown."; qCWarning(scriptengine) << "Trying to save scripts during shutdown.";
return; return;
} }

View file

@ -1118,7 +1118,7 @@ void ScriptManager::timerFired() {
_timerCallCounter++; _timerCallCounter++;
if (_timerCallCounter % 100 == 0) { if (_timerCallCounter % 100 == 0) {
qDebug() << "Script engine: " << _engine->manager()->getFilename() qCDebug(scriptengine) << "Script engine: " << _engine->manager()->getFilename()
<< "timer call count: " << _timerCallCounter << " total time: " << _totalTimeInTimerEvents_s; << "timer call count: " << _timerCallCounter << " total time: " << _totalTimeInTimerEvents_s;
} }
QElapsedTimer callTimer; QElapsedTimer callTimer;
@ -1201,7 +1201,7 @@ void ScriptManager::stopTimer(QTimer *timer) {
} }
QUrl ScriptManager::resolvePath(const QString& include) const { QUrl ScriptManager::resolvePath(const QString& include) const {
//qDebug(scriptengine) << "ScriptManager::resolvePath: getCurrentScriptURLs: " << _engine->getCurrentScriptURLs(); //qCDebug(scriptengine) << "ScriptManager::resolvePath: getCurrentScriptURLs: " << _engine->getCurrentScriptURLs();
QUrl url(include); QUrl url(include);
// first lets check to see if it's already a full URL -- or a Windows path like "c:/" // first lets check to see if it's already a full URL -- or a Windows path like "c:/"
if (include.startsWith("/") || url.scheme().length() == 1) { if (include.startsWith("/") || url.scheme().length() == 1) {
@ -1219,7 +1219,7 @@ QUrl ScriptManager::resolvePath(const QString& include) const {
do { do {
auto contextInfo = context->functionContext(); auto contextInfo = context->functionContext();
parentURL = QUrl(contextInfo->fileName()); parentURL = QUrl(contextInfo->fileName());
//qDebug(scriptengine) << "ScriptManager::resolvePath: URL get: " << parentURL << " backtrace: " << context->backtrace() << " " << _engine->getCurrentScriptURLs(); //qCDebug(scriptengine) << "ScriptManager::resolvePath: URL get: " << parentURL << " backtrace: " << context->backtrace() << " " << _engine->getCurrentScriptURLs();
parentContext = context->parentContext(); parentContext = context->parentContext();
context = parentContext.get(); context = parentContext.get();
} while (parentURL.isRelative() && context); } while (parentURL.isRelative() && context);
@ -1420,7 +1420,7 @@ ScriptValue ScriptManager::newModule(const QString& modulePath, const ScriptValu
// module.require is a bound version of require that always resolves relative to that module's path // module.require is a bound version of require that always resolves relative to that module's path
auto boundRequire = _engine->evaluate("(function(id) { return Script.require(Script.require.resolve(id, this.filename)); })", "(boundRequire)"); auto boundRequire = _engine->evaluate("(function(id) { return Script.require(Script.require.resolve(id, this.filename)); })", "(boundRequire)");
module.setProperty("require", boundRequire, READONLY_PROP_FLAGS); module.setProperty("require", boundRequire, READONLY_PROP_FLAGS);
//qDebug() << "Module object contents" << _engine->scriptValueDebugListMembers(module); //qCDebug(scriptengine) << "Module object contents" << _engine->scriptValueDebugListMembers(module);
return module; return module;
} }
@ -1818,12 +1818,12 @@ QVariant ScriptManager::cloneEntityScriptDetails(const EntityItemID& entityID) {
map["errorInfo"] = "Error: getEntityScriptDetails -- invalid entityID"; map["errorInfo"] = "Error: getEntityScriptDetails -- invalid entityID";
} else { } else {
#ifdef DEBUG_ENTITY_STATES #ifdef DEBUG_ENTITY_STATES
qDebug() << "cloneEntityScriptDetails" << entityID << QThread::currentThread(); qCDebug(scriptengine) << "cloneEntityScriptDetails" << entityID << QThread::currentThread();
#endif #endif
EntityScriptDetails scriptDetails; EntityScriptDetails scriptDetails;
if (getEntityScriptDetails(entityID, scriptDetails)) { if (getEntityScriptDetails(entityID, scriptDetails)) {
#ifdef DEBUG_ENTITY_STATES #ifdef DEBUG_ENTITY_STATES
qDebug() << "gotEntityScriptDetails" << scriptDetails.status << QThread::currentThread(); qCDebug(scriptengine) << "gotEntityScriptDetails" << scriptDetails.status << QThread::currentThread();
#endif #endif
map["isRunning"] = isEntityScriptRunning(entityID); map["isRunning"] = isEntityScriptRunning(entityID);
map["status"] = EntityScriptStatus_::valueToKey(scriptDetails.status).toLower(); map["status"] = EntityScriptStatus_::valueToKey(scriptDetails.status).toLower();
@ -1841,7 +1841,7 @@ QVariant ScriptManager::cloneEntityScriptDetails(const EntityItemID& entityID) {
#endif #endif
} else { } else {
#ifdef DEBUG_ENTITY_STATES #ifdef DEBUG_ENTITY_STATES
qDebug() << "!gotEntityScriptDetails" << QThread::currentThread(); qCDebug(scriptengine) << "!gotEntityScriptDetails" << QThread::currentThread();
#endif #endif
map["isError"] = true; map["isError"] = true;
map["errorInfo"] = "Entity script details unavailable"; map["errorInfo"] = "Entity script details unavailable";
@ -2130,7 +2130,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c
} }
// ENTITY SCRIPT WHITELIST ENDS HERE, uncomment below for original full disabling. // ENTITY SCRIPT WHITELIST ENDS HERE, uncomment below for original full disabling.
// qDebug() << "(disabled entity script)" << entityID.toString() << scriptOrURL; // qCDebug(scriptengine) << "(disabled entity script)" << entityID.toString() << scriptOrURL;
// exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0"); // exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0");
} }
@ -2421,7 +2421,7 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q
} }
} }
if (!callAllowed) { if (!callAllowed) {
qDebug() << "Method [" << methodName << "] not remotely callable."; qCDebug(scriptengine) << "Method [" << methodName << "] not remotely callable.";
} }
} }

View file

@ -259,7 +259,7 @@ public:
* *
* ScriptManagerPointer sm = newScriptManager(ScriptManager::NETWORKLESS_TEST_SCRIPT, scriptSource, scriptFilename); * ScriptManagerPointer sm = newScriptManager(ScriptManager::NETWORKLESS_TEST_SCRIPT, scriptSource, scriptFilename);
* connect(sm.get(), &ScriptManager::printedMessage, [](const QString& message, const QString& engineName){ * connect(sm.get(), &ScriptManager::printedMessage, [](const QString& message, const QString& engineName){
* qDebug() << "Printed message from engine" << engineName << ": " << message; * qCDebug(scriptengine) << "Printed message from engine" << engineName << ": " << message;
* }); * });
* *
* qInfo() << "Running script!"; * qInfo() << "Running script!";

View file

@ -26,6 +26,8 @@
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include "ScriptEngineLogging.h"
class ScriptEngine; class ScriptEngine;
class ScriptValue; class ScriptValue;
class ScriptValueIterator; class ScriptValueIterator;
@ -210,7 +212,7 @@ ScriptValue ScriptValue::call(const ScriptValue& thisObject, const ScriptValueLi
Q_ASSERT(_proxy != nullptr); Q_ASSERT(_proxy != nullptr);
ScriptEnginePointer scriptEngine = _proxy->engine(); ScriptEnginePointer scriptEngine = _proxy->engine();
if (scriptEngine == nullptr) { if (scriptEngine == nullptr) {
qDebug() << "Call to deleted or non-existing script engine"; qCDebug(scriptengine) << "Call to deleted or non-existing script engine";
return ScriptValue(); return ScriptValue();
} }
return _proxy->call(thisObject, args); return _proxy->call(thisObject, args);

View file

@ -933,7 +933,7 @@ ScriptValue meshesToScriptValue(ScriptEngine* engine, const MeshProxyList& in) {
bool meshesFromScriptValue(const ScriptValue& value, MeshProxyList& out) { bool meshesFromScriptValue(const ScriptValue& value, MeshProxyList& out) {
ScriptValueIteratorPointer itr(value.newIterator()); ScriptValueIteratorPointer itr(value.newIterator());
qDebug(scriptengine) << "in meshesFromScriptValue, value.length =" << value.property("length").toInt32(); qCDebug(scriptengine) << "in meshesFromScriptValue, value.length =" << value.property("length").toInt32();
while (itr->hasNext()) { while (itr->hasNext()) {
itr->next(); itr->next();
@ -941,7 +941,7 @@ bool meshesFromScriptValue(const ScriptValue& value, MeshProxyList& out) {
if (meshProxy) { if (meshProxy) {
out.append(meshProxy); out.append(meshProxy);
} else { } else {
qDebug(scriptengine) << "null meshProxy"; qCDebug(scriptengine) << "null meshProxy";
} }
} }
return true; return true;

View file

@ -26,7 +26,7 @@
#include "ScriptManager.h" #include "ScriptManager.h"
Vec3::~Vec3() { Vec3::~Vec3() {
qDebug(scriptengine) << "ScriptMethodV8Proxy destroyed"; qCDebug(scriptengine) << "ScriptMethodV8Proxy destroyed";
printf("ScriptMethodV8Proxy destroyed"); printf("ScriptMethodV8Proxy destroyed");
} }