From 58bc4bcb63924ae10bd9c5a8a8f6639c681f5eea Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Wed, 12 May 2021 12:55:21 +0100 Subject: [PATCH] log info --- code/AssetLib/3DS/3DSLoader.cpp | 2 +- code/AssetLib/AC/ACLoader.cpp | 4 ++-- code/Common/DefaultLogger.cpp | 9 +++++---- include/assimp/Logger.hpp | 21 ++++++++++++--------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/3DS/3DSLoader.cpp b/code/AssetLib/3DS/3DSLoader.cpp index 92fe72bbf..2d77e0f66 100644 --- a/code/AssetLib/3DS/3DSLoader.cpp +++ b/code/AssetLib/3DS/3DSLoader.cpp @@ -305,7 +305,7 @@ void Discreet3DSImporter::ParseEditorChunk() { // print the version number char buff[10]; ASSIMP_itoa10(buff, stream->GetI2()); - ASSIMP_LOG_INFO_F(std::string("3DS file format version: "), buff); + ASSIMP_LOG_INFO_F("3DS file format version: ", buff); } break; }; ASSIMP_3DS_END_CHUNK(); diff --git a/code/AssetLib/AC/ACLoader.cpp b/code/AssetLib/AC/ACLoader.cpp index cba84e8b0..59cfc30dd 100644 --- a/code/AssetLib/AC/ACLoader.cpp +++ b/code/AssetLib/AC/ACLoader.cpp @@ -690,7 +690,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, if (object.subDiv) { if (configEvalSubdivision) { std::unique_ptr div(Subdivider::Create(Subdivider::CATMULL_CLARKE)); - ASSIMP_LOG_INFO("AC3D: Evaluating subdivision surface: " + object.name); + ASSIMP_LOG_INFO_F("AC3D: Evaluating subdivision surface: ", object.name); std::vector cpy(meshes.size() - oldm, nullptr); div->Subdivide(&meshes[oldm], cpy.size(), &cpy.front(), object.subDiv, true); @@ -698,7 +698,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object, // previous meshes are deleted vy Subdivide(). } else { - ASSIMP_LOG_INFO("AC3D: Letting the subdivision surface untouched due to my configuration: " + object.name); + ASSIMP_LOG_INFO_F("AC3D: Letting the subdivision surface untouched due to my configuration: ", object.name); } } } diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index d2e9a2caf..a5c378e03 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -187,13 +187,14 @@ void Logger::verboseDebug(const char *message) { } // ---------------------------------------------------------------------------------- -void Logger::info(const char *message) { - +void Logger::infoInternal(Assimp::Formatter::format f) { + std::string message = f; + // TODO: Should limit sizes in the formatter. // SECURITY FIX: see above - if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { + if (message.length() > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnInfo(message); + return OnInfo(message.c_str()); } // ---------------------------------------------------------------------------------- diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index f68c951fd..2c3ee1085 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -113,8 +113,10 @@ public: // ---------------------------------------------------------------------- /** @brief Writes a info message * @param message Info message*/ - void info(const char* message); - void info(const std::string &message); + template + void info(T&&... args) { + infoInternal(Assimp::Formatter::format(), std::forward(args)...); + } // ---------------------------------------------------------------------- /** @brief Writes a warning message @@ -235,6 +237,13 @@ protected: 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)...); + } + protected: LogSeverity m_Severity; }; @@ -293,12 +302,6 @@ void Logger::error(const std::string &message) { return error(message.c_str()); } -// ---------------------------------------------------------------------------------- -inline -void Logger::info(const std::string &message) { - return info(message.c_str()); -} - } // Namespace Assimp // ------------------------------------------------------------------------------------------------ @@ -315,7 +318,7 @@ void Logger::info(const std::string &message) { Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__)) #define ASSIMP_LOG_INFO_F(string, ...) \ - Assimp::DefaultLogger::get()->info((Assimp::Formatter::format(string), __VA_ARGS__)) + Assimp::DefaultLogger::get()->info((string, __VA_ARGS__)) #define ASSIMP_LOG_WARN(string) \ Assimp::DefaultLogger::get()->warn(string)