Merge pull request #657 from Areloch/SeparateImporterLogFile

Updates asset importer and project importer to output to separate log files into tools/logs
This commit is contained in:
Brian Roberts 2021-11-03 21:15:51 -05:00 committed by GitHub
commit e4428cf75a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 195 additions and 100 deletions

View file

@ -18,6 +18,7 @@
#include "materials/materialManager.h"
#include "console/persistenceManager.h"
#include "core/util/timeClass.h"
ConsoleDocClass(AssetImportConfig,
"@brief Defines properties for an AssetImprotConfig object.\n"
@ -506,7 +507,8 @@ AssetImporter::AssetImporter() :
isReimport(false),
assetHeirarchyChanged(false),
importLogBuffer(""),
activeImportConfig(nullptr)
activeImportConfig(nullptr),
mDumpLogs(true)
{
}
@ -534,6 +536,7 @@ void AssetImporter::initPersistFields()
addField("targetModuleId", TypeRealString, Offset(targetModuleId, AssetImporter), "The Id of the module the assets are to be imported into");
addField("finalImportedAssetPath", TypeRealString, Offset(finalImportedAssetPath, AssetImporter), "The Id of the module the assets are to be imported into");
addField("targetPath", TypeRealString, Offset(targetPath, AssetImporter), "The path any imported assets are placed in as their destination");
addField("dumpLogs", TypeBool, Offset(mDumpLogs, AssetImporter), "Indicates if the importer always dumps its logs or not");
}
//
@ -924,9 +927,41 @@ String AssetImporter::getActivityLogLine(U32 line)
void AssetImporter::dumpActivityLog()
{
for (U32 i = 0; i < activityLog.size(); i++)
if (!mDumpLogs)
return;
FileObject logFile;
//If there's nothing logged, don't bother
if (activityLog.size() == 0)
return;
Torque::Time::DateTime curTime;
Torque::Time::getCurrentDateTime(curTime);
String logName = String("tools/logs/AssetImportLog_") + String::ToString(curTime.year + 1900) + "-" +
String::ToString(curTime.month + 1) + "-" + String::ToString(curTime.day) + "_" +
String::ToString(curTime.hour) + "-" + String::ToString(curTime.minute) + "-" + String::ToString(curTime.second)
+ "-" + String::ToString(curTime.microsecond) + ".log";
if (logFile.openForWrite(logName.c_str()))
{
Con::printf(activityLog[i].c_str());
for (U32 i = 0; i < activityLog.size(); i++)
{
logFile.writeLine((const U8*)activityLog[i].c_str());
}
logFile.close();
Con::warnf("Asset Import log file dumped to: %s", logName.c_str());
}
else
{
Con::errorf("Error: Failed to open log file for writing! Dumping log results to console!");
for (U32 i = 0; i < activityLog.size(); i++)
{
Con::printf(activityLog[i].c_str());
}
}
}
@ -2383,6 +2418,7 @@ void AssetImporter::importAssets(AssetImportObject* assetItem)
{
dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Unable to find moduleId %s", targetModuleId.c_str());
activityLog.push_back(importLogBuffer);
dumpActivityLog();
return;
}
@ -2483,6 +2519,8 @@ void AssetImporter::importAssets(AssetImportObject* assetItem)
//recurse if needed
importAssets(item);
}
dumpActivityLog();
}
//

View file

@ -647,6 +647,8 @@ class AssetImporter : public SimObject
/// </summary>
String finalImportedAssetPath;
bool mDumpLogs;
public:
AssetImporter();
virtual ~AssetImporter();

View file

@ -44,7 +44,7 @@ DefineEngineMethod(AssetImporter, getActivityLogLine, String, (S32 i), (0),
"Creates a new script asset using the targetFilePath.\n"
"@return The bool result of calling exec")
{
return object->getActivityLogLine(0);
return object->getActivityLogLine(i);
}
DefineEngineMethod(AssetImporter, autoImportFile, String, (String path, String typeHint), ("", ""),

View file

@ -2841,3 +2841,21 @@ DefineEngineFunction( getStringHash, S32, (const char* _inString, bool _sensitiv
else
return S32(String(_inString).getHashCaseInsensitive());
}
//-----------------------------------------------------------------------------
DefineEngineFunction(getTimestamp, const char*, (), ,
"Gets datetime string.\n\n"
"@return YYYY-mm-DD_hh-MM-ss formatted date time string.")
{
Torque::Time::DateTime curTime;
Torque::Time::getCurrentDateTime(curTime);
String timestampStr = String::ToString(curTime.year + 1900) + "-" +
String::ToString(curTime.month + 1) + "-" + String::ToString(curTime.day) + "_" +
String::ToString(curTime.hour) + "-" + String::ToString(curTime.minute) + "-" + String::ToString(curTime.second);
const char* returnBuffer = Con::getReturnBuffer(timestampStr);
return returnBuffer;
}