Log debug

pull/3905/head
Malcolm Tyrrell 2021-05-13 09:56:42 +01:00
parent ca698c3e49
commit 89584c167a
5 changed files with 28 additions and 28 deletions

View File

@ -297,8 +297,8 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
} }
if ( !DefaultLogger::isNullLogger()){ if ( !DefaultLogger::isNullLogger()){
ASSIMP_LOG_DEBUG((Formatter::format(),"STEP: got ",map.size()," object records with ", ASSIMP_LOG_DEBUG_F("STEP: got ",map.size()," object records with ",
db.GetRefs().size()," inverse index entries")); db.GetRefs().size()," inverse index entries");
} }
} }

View File

@ -163,15 +163,14 @@ Logger *DefaultLogger::create(const char *name /*= "AssimpLog.txt"*/,
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
void Logger::debug(const char *message) { void Logger::debugInternal(Assimp::Formatter::format f) {
std::string message = f;
// SECURITY FIX: otherwise it's easy to produce overruns since // TODO: Should limit sizes in the formatter.
// sometimes importers will include data from the input file // SECURITY FIX: see above
// (i.e. node names) in their messages. if (message.length() > MAX_LOG_MESSAGE_LENGTH) {
if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) {
return; return;
} }
return OnDebug(message); return OnDebug(message.c_str());
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------

View File

@ -103,7 +103,7 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene)
if( !isNecessary ) 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; 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 // recurse through all nodes and translate the node's mesh indices to fit the new mesh array
UpdateNode( pScene->mRootNode); 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." );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -99,10 +99,12 @@ public:
virtual ~Logger(); virtual ~Logger();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Writes a debug message /** @brief Writes a info message
* @param message Debug message*/ * @param message Info message*/
void debug(const char* message); template<typename... T>
void debug(const std::string &message); void debug(T&&... args) {
debugInternal(Assimp::Formatter::format(), std::forward<T>(args)...);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Writes a debug message /** @brief Writes a debug message
@ -232,22 +234,27 @@ protected:
virtual void OnError(const char* message) = 0; virtual void OnError(const char* message) = 0;
protected: protected:
void debugInternal(Assimp::Formatter::format f);
void warnInternal(Assimp::Formatter::format f); void warnInternal(Assimp::Formatter::format f);
void infoInternal(Assimp::Formatter::format f);
void errorInternal(Assimp::Formatter::format f);
template<typename... T, typename U>
void debugInternal(Assimp::Formatter::format f, U&& u, T&&... args) {
warnInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...);
}
template<typename... T, typename U> template<typename... T, typename U>
void warnInternal(Assimp::Formatter::format f, U&& u, T&&... args) { void warnInternal(Assimp::Formatter::format f, U&& u, T&&... args) {
warnInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...); warnInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...);
} }
void infoInternal(Assimp::Formatter::format f);
template<typename... T, typename U> template<typename... T, typename U>
void infoInternal(Assimp::Formatter::format f, U&& u, T&&... args) { void infoInternal(Assimp::Formatter::format f, U&& u, T&&... args) {
infoInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...); infoInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...);
} }
void errorInternal(Assimp::Formatter::format f);
template<typename... T, typename U> template<typename... T, typename U>
void errorInternal(Assimp::Formatter::format f, U&& u, T&&... args) { void errorInternal(Assimp::Formatter::format f, U&& u, T&&... args) {
errorInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...); errorInternal(std::move(f << std::forward<U>(u)), std::forward<T>(args)...);
@ -294,12 +301,6 @@ Logger::LogSeverity Logger::getLogSeverity() const {
return m_Severity; return m_Severity;
} }
// ----------------------------------------------------------------------------------
inline
void Logger::debug(const std::string &message) {
return debug(message.c_str());
}
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
inline void Logger::verboseDebug(const std::string &message) { inline void Logger::verboseDebug(const std::string &message) {
return verboseDebug(message.c_str()); return verboseDebug(message.c_str());
@ -315,7 +316,7 @@ inline void Logger::verboseDebug(const std::string &message) {
Assimp::DefaultLogger::get()->error((string, __VA_ARGS__)) Assimp::DefaultLogger::get()->error((string, __VA_ARGS__))
#define ASSIMP_LOG_DEBUG_F(string, ...) \ #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, ...) \ #define ASSIMP_LOG_VERBOSE_DEBUG_F(string, ...) \
Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__)) Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__))

View File

@ -76,7 +76,7 @@ public:
/** Start a named timer */ /** Start a named timer */
void BeginRegion(const std::string& region) { void BeginRegion(const std::string& region) {
regions[region] = std::chrono::system_clock::now(); 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<double> elapsedSeconds = std::chrono::system_clock::now() - regions[region]; std::chrono::duration<double> 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: private: