From 78145f1425b0ad81f39c1a2c5c26e70fb9174749 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Thu, 13 May 2021 10:08:59 +0100 Subject: [PATCH] log verboseDebug --- code/AssetLib/ASE/ASELoader.cpp | 2 +- code/AssetLib/COB/COBLoader.cpp | 3 +-- code/AssetLib/DXF/DXFHelper.h | 2 +- code/Common/DefaultLogger.cpp | 12 ++++++------ include/assimp/Logger.hpp | 21 ++++++++++++--------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/code/AssetLib/ASE/ASELoader.cpp b/code/AssetLib/ASE/ASELoader.cpp index e1b9c5b83..a05c3c5e9 100644 --- a/code/AssetLib/ASE/ASELoader.cpp +++ b/code/AssetLib/ASE/ASELoader.cpp @@ -614,7 +614,7 @@ void ASEImporter::AddNodes(const std::vector &nodes, node->mNumChildren++; // What we did is so great, it is at least worth a debug message - ASSIMP_LOG_VERBOSE_DEBUG("ASE: Generating separate target node (" + snode->mName + ")"); + ASSIMP_LOG_VERBOSE_DEBUG_F("ASE: Generating separate target node (", snode->mName, ")"); } } diff --git a/code/AssetLib/COB/COBLoader.cpp b/code/AssetLib/COB/COBLoader.cpp index a6e9d4218..29e8e9de1 100644 --- a/code/AssetLib/COB/COBLoader.cpp +++ b/code/AssetLib/COB/COBLoader.cpp @@ -301,8 +301,7 @@ aiNode *COBImporter::BuildNodes(const Node &root, const Scene &scin, aiScene *fi } std::unique_ptr defmat; if (!min) { - ASSIMP_LOG_VERBOSE_DEBUG(format() << "Could not resolve material index " - << reflist.first << " - creating default material for this slot"); + ASSIMP_LOG_VERBOSE_DEBUG_F("Could not resolve material index ", reflist.first, " - creating default material for this slot"); defmat.reset(min = new Material()); } diff --git a/code/AssetLib/DXF/DXFHelper.h b/code/AssetLib/DXF/DXFHelper.h index f7fc470e8..5099b43ee 100644 --- a/code/AssetLib/DXF/DXFHelper.h +++ b/code/AssetLib/DXF/DXFHelper.h @@ -135,7 +135,7 @@ public: for(;splitter->length() && splitter->at(0) != '}'; splitter++, cnt++); splitter++; - ASSIMP_LOG_VERBOSE_DEBUG((Formatter::format("DXF: skipped over control group ("),cnt," lines)")); + ASSIMP_LOG_VERBOSE_DEBUG_F("DXF: skipped over control group (",cnt," lines)"); } } catch(std::logic_error&) { ai_assert(!splitter); diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index 03a0a80de..e12276ea9 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -174,14 +174,14 @@ void Logger::debugInternal(Assimp::Formatter::format f) { } // ---------------------------------------------------------------------------------- -void Logger::verboseDebug(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::verboseDebugInternal(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 OnVerboseDebug(message); + return OnVerboseDebug(message.c_str()); } // ---------------------------------------------------------------------------------- diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index 475b19aa6..3d1588f61 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -109,8 +109,10 @@ public: // ---------------------------------------------------------------------- /** @brief Writes a debug message * @param message Debug message*/ - void verboseDebug(const char *message); - void verboseDebug(const std::string &message); + template + void verboseDebug(T&&... args) { + verboseDebugInternal(Assimp::Formatter::format(), std::forward(args)...); + } // ---------------------------------------------------------------------- /** @brief Writes a info message @@ -236,13 +238,19 @@ protected: protected: void debugInternal(Assimp::Formatter::format f); + void verboseDebugInternal(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)...); + debugInternal(std::move(f << std::forward(u)), std::forward(args)...); + } + + template + void verboseDebugInternal(Assimp::Formatter::format f, U&& u, T&&... args) { + verboseDebugInternal(std::move(f << std::forward(u)), std::forward(args)...); } template @@ -301,11 +309,6 @@ Logger::LogSeverity Logger::getLogSeverity() const { return m_Severity; } -// ---------------------------------------------------------------------------------- -inline void Logger::verboseDebug(const std::string &message) { - return verboseDebug(message.c_str()); -} - } // Namespace Assimp // ------------------------------------------------------------------------------------------------ @@ -319,7 +322,7 @@ inline void Logger::verboseDebug(const std::string &message) { Assimp::DefaultLogger::get()->debug((string, __VA_ARGS__)) #define ASSIMP_LOG_VERBOSE_DEBUG_F(string, ...) \ - Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__)) + Assimp::DefaultLogger::get()->verboseDebug((string, __VA_ARGS__)) #define ASSIMP_LOG_INFO_F(string, ...) \ Assimp::DefaultLogger::get()->info((string, __VA_ARGS__))