Add ThreadID to default log stream output.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@106 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
kimmi 2008-08-11 19:17:33 +00:00
parent cefecc1fe7
commit b5c54703d0
5 changed files with 130 additions and 98 deletions

View File

@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FileLogStream.h"
#include <iostream>
#include <sstream>
namespace Assimp
{
@ -68,17 +69,24 @@ struct LogStreamInfo
{
// empty
}
// Destructor
~LogStreamInfo()
{
// empty
}
};
// ---------------------------------------------------------------------------
// Creates the only singleton instance
Logger *DefaultLogger::create(const std::string &name, LogSeverity severity)
{
m_pLogger = new DefaultLogger( name, severity );
if ( NULL == m_pLogger )
m_pLogger = new DefaultLogger( name, severity );
return m_pLogger;
}
// ---------------------------------------------------------------------------
void DefaultLogger::set (Logger *logger)
void DefaultLogger::set( Logger *logger )
{
if (!logger)
{
@ -110,20 +118,20 @@ void DefaultLogger::kill()
// ---------------------------------------------------------------------------
// Debug message
void DefaultLogger::debug(const std::string &message)
void DefaultLogger::debug( const std::string &message )
{
if ( m_Severity == Logger::NORMAL )
return;
const std::string msg( "Debug: " + message );
const std::string msg( "Debug, thread " + getThreadID() + " :" + message );
writeToStreams( msg, Logger::DEBUGGING );
}
// ---------------------------------------------------------------------------
// Logs an info
void DefaultLogger::info(const std::string &message)
void DefaultLogger::info( const std::string &message )
{
const std::string msg( "Info: " + message );
const std::string msg( "Info: " + getThreadID() + " :" + message );
writeToStreams( msg , Logger::INFO );
}
@ -131,7 +139,7 @@ void DefaultLogger::info(const std::string &message)
// Logs a warning
void DefaultLogger::warn( const std::string &message )
{
const std::string msg( "Warn: " + message );
const std::string msg( "Warn: " + getThreadID() + " :"+ message );
writeToStreams( msg, Logger::WARN );
}
@ -139,7 +147,7 @@ void DefaultLogger::warn( const std::string &message )
// Logs an error
void DefaultLogger::error( const std::string &message )
{
const std::string msg( "Error: " + message );
const std::string msg( "Error: "+ getThreadID() + " :" + message );
writeToStreams( msg, Logger::ERR );
}
@ -258,8 +266,7 @@ void DefaultLogger::writeToStreams(const std::string &message,
{
if ( message.empty() )
return;
for ( ConstStreamIt it = this->m_StreamArray.begin();
for ( ConstStreamIt it = m_StreamArray.begin();
it != m_StreamArray.end();
++it)
{
@ -276,6 +283,26 @@ void DefaultLogger::writeToStreams(const std::string &message,
}
}
// ---------------------------------------------------------------------------
// Returns thread id, if not supported only a zero will be returned.
std::string DefaultLogger::getThreadID()
{
std::string thread_id( "0" );
#ifdef WIN32
HANDLE hThread = GetCurrentThread();
if ( hThread )
{
std::stringstream thread_msg;
thread_msg << ::GetCurrentThreadId() << " ";
return thread_msg.str();
}
else
return thread_id;
#else
return thread_id;
#endif
}
// ---------------------------------------------------------------------------
} // Namespace Assimp

View File

@ -653,11 +653,11 @@
</FileConfiguration>
</File>
<File
RelativePath="..\..\include\cppunit\ui\text\TextTestRunner.h"
RelativePath="..\..\include\cppunit\TextTestRunner.h"
>
</File>
<File
RelativePath="..\..\include\cppunit\TextTestRunner.h"
RelativePath="..\..\include\cppunit\ui\text\TextTestRunner.h"
>
</File>
</Filter>
@ -2694,11 +2694,11 @@
>
</File>
<File
RelativePath="Makefile.am"
RelativePath="..\..\include\cppunit\Makefile.am"
>
</File>
<File
RelativePath="..\..\include\cppunit\Makefile.am"
RelativePath="Makefile.am"
>
</File>
</Files>

View File

@ -131,6 +131,11 @@ private:
/** @brief Writes message into a file */
void writeToStreams(const std::string &message, ErrorSeverity ErrorSev );
/** @brief Returns the thread id.
* @remark This is an OS specific feature, if not supported, a zero will be returned.
*/
std::string getThreadID();
private:
// Aliases for stream container
typedef std::vector<LogStreamInfo*> StreamArray;

View File

@ -7,7 +7,7 @@ namespace Assimp
{
// ---------------------------------------------------------------------------
/** @class LogStream
* @brief Abstract interface for log stream implementations.
* @brief Abstract interface for log stream implementations.
*/
class ASSIMP_API LogStream
{

View File

@ -99,6 +99,87 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)..\..\tools\build\$(ConfigurationName)_$(PlatformName)"
IntermediateDirectory="$(SolutionDir)..\..\tools\build\$(ConfigurationName)_$(PlatformName)\obj"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(DXSDK_DIR)include&quot;;..\..\include;..\..\code"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="d3d9.lib d3dx9.lib comdlg32.lib assimp.lib winmm.lib comctl32.lib user32.lib advapi32.lib shell32.lib Gdi32.lib"
OutputFile="$(OutDir)\assimpview32.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib\assimp_release_win32;&quot;$(DXSDK_DIR)lib\x86&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)..\..\tools\build\$(ConfigurationName)_$(PlatformName)"
@ -181,87 +262,6 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)..\..\tools\build\$(ConfigurationName)_$(PlatformName)"
IntermediateDirectory="$(SolutionDir)..\..\tools\build\$(ConfigurationName)_$(PlatformName)\obj"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(DXSDK_DIR)include&quot;;..\..\include;..\..\code"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="d3d9.lib d3dx9.lib comdlg32.lib assimp.lib winmm.lib comctl32.lib user32.lib advapi32.lib shell32.lib Gdi32.lib"
OutputFile="$(OutDir)\assimpview32.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib\assimp_release_win32;&quot;$(DXSDK_DIR)lib\x86&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)..\..\tools\build\$(ConfigurationName)_$(PlatformName)"
@ -417,7 +417,7 @@
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
@ -425,7 +425,7 @@
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"