2011-10-03 14:41:19 -04:00
|
|
|
|
2012-01-29 14:28:19 -05:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#include <time.h>
|
2012-01-29 14:28:19 -05:00
|
|
|
#include "cLog.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
cMCLogger* cMCLogger::s_MCLogger = 0;
|
|
|
|
|
|
|
|
cMCLogger* cMCLogger::GetInstance()
|
|
|
|
{
|
|
|
|
return s_MCLogger;
|
|
|
|
}
|
|
|
|
|
2012-02-01 08:43:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cMCLogger::cMCLogger()
|
|
|
|
{
|
2012-02-01 08:43:47 -05:00
|
|
|
AString FileName;
|
|
|
|
Printf(FileName, "LOG_%d.txt", (int)time(0) );
|
|
|
|
m_Log = new cLog(FileName);
|
2011-10-03 14:41:19 -04:00
|
|
|
m_Log->Log("--- Started Log ---");
|
|
|
|
|
|
|
|
s_MCLogger = this;
|
|
|
|
}
|
|
|
|
|
2012-02-01 08:43:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cMCLogger::cMCLogger( char* a_File )
|
|
|
|
{
|
|
|
|
m_Log = new cLog( a_File );
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cMCLogger::~cMCLogger()
|
|
|
|
{
|
|
|
|
m_Log->Log("--- Stopped Log ---");
|
|
|
|
delete m_Log;
|
2012-02-02 02:47:19 -05:00
|
|
|
if (this == s_MCLogger)
|
|
|
|
s_MCLogger = NULL;
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
|
|
|
|
{
|
|
|
|
switch( a_LogType )
|
|
|
|
{
|
2012-02-02 02:47:19 -05:00
|
|
|
case 0:
|
|
|
|
Log(a_Text, 0);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Info(a_Text, 0);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Warn(a_Text, 0);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Error(a_Text, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Log(a_Text, 0);
|
|
|
|
break;
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cMCLogger::Log(const char* a_Format, va_list a_ArgList)
|
|
|
|
{
|
2012-02-02 02:47:19 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2011-10-03 14:41:19 -04:00
|
|
|
SetColor( 0x7 ); // 0x7 is default grey color
|
|
|
|
m_Log->Log( a_Format, a_ArgList );
|
2012-02-02 02:47:19 -05:00
|
|
|
SetColor(0x07); // revert color back
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cMCLogger::Info(const char* a_Format, va_list a_ArgList)
|
|
|
|
{
|
2012-02-02 02:47:19 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2011-10-03 14:41:19 -04:00
|
|
|
// for( int i = 0; i < 16; i++)
|
|
|
|
// {
|
|
|
|
// for( int j = 0; j < 16; j++ )
|
|
|
|
// {
|
|
|
|
// SetConsoleTextAttribute( hConsole, i | (j<<4) );
|
|
|
|
// printf("0x%x", (i|j<<4));
|
|
|
|
// }
|
|
|
|
// printf("\n");
|
|
|
|
// }
|
|
|
|
|
|
|
|
SetColor( 0xe ); // 0xe is yellow
|
|
|
|
m_Log->Log( a_Format, a_ArgList );
|
2012-02-02 02:47:19 -05:00
|
|
|
SetColor(0x07); // revert color back
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cMCLogger::Warn(const char* a_Format, va_list a_ArgList)
|
|
|
|
{
|
2012-02-02 02:47:19 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2011-10-03 14:41:19 -04:00
|
|
|
SetColor( 0xc ); // 0xc is red
|
|
|
|
m_Log->Log( a_Format, a_ArgList );
|
2012-02-02 02:47:19 -05:00
|
|
|
SetColor(0x07); // revert color back
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cMCLogger::Error(const char* a_Format, va_list a_ArgList)
|
|
|
|
{
|
2012-02-02 02:47:19 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2011-10-03 14:41:19 -04:00
|
|
|
SetColor( 0xc0 ); // 0xc0 is red bg and black text
|
|
|
|
m_Log->Log( a_Format, a_ArgList );
|
2012-02-02 02:47:19 -05:00
|
|
|
SetColor(0x07); // revert color back
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cMCLogger::SetColor( unsigned char a_Color )
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
|
|
|
|
SetConsoleTextAttribute( hConsole, a_Color );
|
|
|
|
#else
|
|
|
|
(void)a_Color;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-02 02:47:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Global functions
|
|
|
|
void LOG(const char* a_Format, ...)
|
|
|
|
{
|
|
|
|
va_list argList;
|
|
|
|
va_start(argList, a_Format);
|
|
|
|
cMCLogger::GetInstance()->Log( a_Format, argList );
|
|
|
|
va_end(argList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LOGINFO(const char* a_Format, ...)
|
|
|
|
{
|
|
|
|
va_list argList;
|
|
|
|
va_start(argList, a_Format);
|
|
|
|
cMCLogger::GetInstance()->Info( a_Format, argList );
|
|
|
|
va_end(argList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LOGWARN(const char* a_Format, ...)
|
|
|
|
{
|
|
|
|
va_list argList;
|
|
|
|
va_start(argList, a_Format);
|
|
|
|
cMCLogger::GetInstance()->Warn( a_Format, argList );
|
|
|
|
va_end(argList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LOGERROR(const char* a_Format, ...)
|
|
|
|
{
|
|
|
|
va_list argList;
|
|
|
|
va_start(argList, a_Format);
|
|
|
|
cMCLogger::GetInstance()->Error( a_Format, argList );
|
|
|
|
va_end(argList);
|
|
|
|
}
|
2012-02-18 12:51:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|