From 89584c167aaf341a6d717083bb9a52a4c1b0ace1 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Thu, 13 May 2021 09:56:42 +0100 Subject: [PATCH] Log debug --- code/AssetLib/STEPParser/STEPFileReader.cpp | 4 +-- code/Common/DefaultLogger.cpp | 13 ++++---- .../SplitByBoneCountProcess.cpp | 4 +-- include/assimp/Logger.hpp | 31 ++++++++++--------- include/assimp/Profiler.h | 4 +-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/code/AssetLib/STEPParser/STEPFileReader.cpp b/code/AssetLib/STEPParser/STEPFileReader.cpp index cbf8c07c2..1ed5ab7d2 100644 --- a/code/AssetLib/STEPParser/STEPFileReader.cpp +++ b/code/AssetLib/STEPParser/STEPFileReader.cpp @@ -297,8 +297,8 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, } if ( !DefaultLogger::isNullLogger()){ - ASSIMP_LOG_DEBUG((Formatter::format(),"STEP: got ",map.size()," object records with ", - db.GetRefs().size()," inverse index entries")); + ASSIMP_LOG_DEBUG_F("STEP: got ",map.size()," object records with ", + db.GetRefs().size()," inverse index entries"); } } diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index e468d72ca..03a0a80de 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -163,15 +163,14 @@ Logger *DefaultLogger::create(const char *name /*= "AssimpLog.txt"*/, } // ---------------------------------------------------------------------------------- -void Logger::debug(const char *message) { - - // SECURITY FIX: otherwise it's easy to produce overruns since - // sometimes importers will include data from the input file - // (i.e. node names) in their messages. - if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { +void Logger::debugInternal(Assimp::Formatter::format f) { + std::string message = f; + // TODO: Should limit sizes in the formatter. + // SECURITY FIX: see above + if (message.length() > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnDebug(message); + return OnDebug(message.c_str()); } // ---------------------------------------------------------------------------------- diff --git a/code/PostProcessing/SplitByBoneCountProcess.cpp b/code/PostProcessing/SplitByBoneCountProcess.cpp index 1f4170a6a..f7dffb8f2 100644 --- a/code/PostProcessing/SplitByBoneCountProcess.cpp +++ b/code/PostProcessing/SplitByBoneCountProcess.cpp @@ -103,7 +103,7 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene) if( !isNecessary ) { - ASSIMP_LOG_DEBUG( format() << "SplitByBoneCountProcess early-out: no meshes with more than " << mMaxBoneCount << " bones." ); + ASSIMP_LOG_DEBUG_F("SplitByBoneCountProcess early-out: no meshes with more than ", mMaxBoneCount, " bones." ); return; } @@ -151,7 +151,7 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene) // recurse through all nodes and translate the node's mesh indices to fit the new mesh array UpdateNode( pScene->mRootNode); - ASSIMP_LOG_DEBUG( format() << "SplitByBoneCountProcess end: split " << mSubMeshIndices.size() << " meshes into " << meshes.size() << " submeshes." ); + ASSIMP_LOG_DEBUG_F( "SplitByBoneCountProcess end: split ", mSubMeshIndices.size(), " meshes into ", meshes.size(), " submeshes." ); } // ------------------------------------------------------------------------------------------------ diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index 07a26c053..475b19aa6 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -99,10 +99,12 @@ public: virtual ~Logger(); // ---------------------------------------------------------------------- - /** @brief Writes a debug message - * @param message Debug message*/ - void debug(const char* message); - void debug(const std::string &message); + /** @brief Writes a info message + * @param message Info message*/ + template + void debug(T&&... args) { + debugInternal(Assimp::Formatter::format(), std::forward(args)...); + } // ---------------------------------------------------------------------- /** @brief Writes a debug message @@ -232,22 +234,27 @@ protected: virtual void OnError(const char* message) = 0; protected: + + void debugInternal(Assimp::Formatter::format f); void warnInternal(Assimp::Formatter::format f); + void infoInternal(Assimp::Formatter::format f); + void errorInternal(Assimp::Formatter::format f); + + template + void debugInternal(Assimp::Formatter::format f, U&& u, T&&... args) { + warnInternal(std::move(f << std::forward(u)), std::forward(args)...); + } template void warnInternal(Assimp::Formatter::format f, U&& u, T&&... args) { warnInternal(std::move(f << std::forward(u)), std::forward(args)...); } - void infoInternal(Assimp::Formatter::format f); - template void infoInternal(Assimp::Formatter::format f, U&& u, T&&... args) { infoInternal(std::move(f << std::forward(u)), std::forward(args)...); } - void errorInternal(Assimp::Formatter::format f); - template void errorInternal(Assimp::Formatter::format f, U&& u, T&&... args) { errorInternal(std::move(f << std::forward(u)), std::forward(args)...); @@ -294,12 +301,6 @@ Logger::LogSeverity Logger::getLogSeverity() const { return m_Severity; } -// ---------------------------------------------------------------------------------- -inline -void Logger::debug(const std::string &message) { - return debug(message.c_str()); -} - // ---------------------------------------------------------------------------------- inline void Logger::verboseDebug(const std::string &message) { return verboseDebug(message.c_str()); @@ -315,7 +316,7 @@ inline void Logger::verboseDebug(const std::string &message) { Assimp::DefaultLogger::get()->error((string, __VA_ARGS__)) #define ASSIMP_LOG_DEBUG_F(string, ...) \ - Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__)) + Assimp::DefaultLogger::get()->debug((string, __VA_ARGS__)) #define ASSIMP_LOG_VERBOSE_DEBUG_F(string, ...) \ Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__)) diff --git a/include/assimp/Profiler.h b/include/assimp/Profiler.h index 5f9fa52aa..566ea84e1 100644 --- a/include/assimp/Profiler.h +++ b/include/assimp/Profiler.h @@ -76,7 +76,7 @@ public: /** Start a named timer */ void BeginRegion(const std::string& region) { regions[region] = std::chrono::system_clock::now(); - ASSIMP_LOG_DEBUG((format("START `"),region,"`")); + ASSIMP_LOG_DEBUG_F("START `",region,"`"); } @@ -88,7 +88,7 @@ public: } std::chrono::duration elapsedSeconds = std::chrono::system_clock::now() - regions[region]; - ASSIMP_LOG_DEBUG((format("END `"),region,"`, dt= ", elapsedSeconds.count()," s")); + ASSIMP_LOG_DEBUG_F("END `",region,"`, dt= ", elapsedSeconds.count()," s"); } private: