add debug logger
This commit is contained in:
parent
b3ef8242db
commit
dc5774a698
@ -765,6 +765,9 @@ bool CSourceAppSystemGroup::Create()
|
|||||||
|
|
||||||
bool CSourceAppSystemGroup::PreInit()
|
bool CSourceAppSystemGroup::PreInit()
|
||||||
{
|
{
|
||||||
|
if ( !CommandLine()->FindParm( "-nolog" ) )
|
||||||
|
DebugLogger()->Init("engine.log");
|
||||||
|
|
||||||
CreateInterfaceFn factory = GetFactory();
|
CreateInterfaceFn factory = GetFactory();
|
||||||
ConnectTier1Libraries( &factory, 1 );
|
ConnectTier1Libraries( &factory, 1 );
|
||||||
ConVar_Register( );
|
ConVar_Register( );
|
||||||
|
@ -48,6 +48,14 @@
|
|||||||
|
|
||||||
class Color;
|
class Color;
|
||||||
|
|
||||||
|
class IDbgLogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Init(const char *logfile) = 0;
|
||||||
|
virtual void Write(const char *data) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
PLATFORM_INTERFACE IDbgLogger *DebugLogger();
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Usage model for the Dbg library
|
// Usage model for the Dbg library
|
||||||
|
@ -49,6 +49,77 @@
|
|||||||
// memdbgon must be the last include file in a .cpp file!!!
|
// memdbgon must be the last include file in a .cpp file!!!
|
||||||
#include "tier0/memdbgon.h"
|
#include "tier0/memdbgon.h"
|
||||||
|
|
||||||
|
class CDbgLogger : public IDbgLogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CDbgLogger();
|
||||||
|
~CDbgLogger();
|
||||||
|
|
||||||
|
void Init(const char *logfile);
|
||||||
|
void Write(const char *data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FILE *file;
|
||||||
|
float flStartTime;
|
||||||
|
bool bShouldLog;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
CDbgLogger::CDbgLogger()
|
||||||
|
{
|
||||||
|
bShouldLog = false;
|
||||||
|
flStartTime = Plat_FloatTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDbgLogger::Init(const char *logfile)
|
||||||
|
{
|
||||||
|
time_t timeCur;
|
||||||
|
struct tm tmStruct;
|
||||||
|
|
||||||
|
char szTime[256];
|
||||||
|
|
||||||
|
bShouldLog = true;
|
||||||
|
|
||||||
|
time( &timeCur );
|
||||||
|
Plat_gmtime( &timeCur, &tmStruct );
|
||||||
|
Plat_ctime( &timeCur, szTime, sizeof(szTime) );
|
||||||
|
|
||||||
|
file = fopen(logfile, "w+");
|
||||||
|
fprintf(file, ">>> Engine started at %s\n", szTime);
|
||||||
|
fflush(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
CDbgLogger::~CDbgLogger()
|
||||||
|
{
|
||||||
|
if( !bShouldLog )
|
||||||
|
return;
|
||||||
|
|
||||||
|
time_t timeCur;
|
||||||
|
struct tm tmStruct;
|
||||||
|
|
||||||
|
char szTime[256];
|
||||||
|
|
||||||
|
time( &timeCur );
|
||||||
|
Plat_gmtime( &timeCur, &tmStruct );
|
||||||
|
Plat_ctime( &timeCur, szTime, sizeof(szTime) );
|
||||||
|
|
||||||
|
fprintf(file, "\n>>> Engine closed at %s\n", szTime);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDbgLogger::Write(const char *data)
|
||||||
|
{
|
||||||
|
if( !bShouldLog )
|
||||||
|
return;
|
||||||
|
|
||||||
|
fprintf(file, "[%.4f] ", Plat_FloatTime() - flStartTime);
|
||||||
|
fprintf(file, "%s", data);
|
||||||
|
fflush(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CDbgLogger g_DbgLogger;
|
||||||
|
IDbgLogger *DebugLogger() { return &g_DbgLogger; }
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// internal structures
|
// internal structures
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -275,7 +346,7 @@ DBG_INTERFACE void _SpewInfo( SpewType_t type, const tchar* pFile, int line )
|
|||||||
|
|
||||||
static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, int nLevel, const Color *pColor, const tchar* pMsgFormat, va_list args )
|
static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, int nLevel, const Color *pColor, const tchar* pMsgFormat, va_list args )
|
||||||
{
|
{
|
||||||
tchar pTempBuffer[5020];
|
tchar pTempBuffer[8192];
|
||||||
|
|
||||||
assert( _tcslen( pMsgFormat ) < sizeof( pTempBuffer) ); // check that we won't artifically truncate the string
|
assert( _tcslen( pMsgFormat ) < sizeof( pTempBuffer) ); // check that we won't artifically truncate the string
|
||||||
|
|
||||||
@ -319,6 +390,7 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i
|
|||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
__android_log_print( ANDROID_LOG_INFO, "SRCENG", "%s", pTempBuffer );
|
__android_log_print( ANDROID_LOG_INFO, "SRCENG", "%s", pTempBuffer );
|
||||||
#endif
|
#endif
|
||||||
|
g_DbgLogger.Write( pTempBuffer );
|
||||||
|
|
||||||
g_pSpewInfo = &spewInfo;
|
g_pSpewInfo = &spewInfo;
|
||||||
ret = s_SpewOutputFunc( spewType, pTempBuffer );
|
ret = s_SpewOutputFunc( spewType, pTempBuffer );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user