From 865216b15a4cfb836dddcb9bf66532b4f46497a3 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 2 Feb 2012 07:47:19 +0000 Subject: cSocket API fix (possible invalid pointer) cMCLogger slight change (CS ptr -> member) git-svn-id: http://mc-server.googlecode.com/svn/trunk@222 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cMCLogger.cpp | 84 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 28 deletions(-) (limited to 'source/cMCLogger.cpp') diff --git a/source/cMCLogger.cpp b/source/cMCLogger.cpp index b3f43333f..c1571a195 100644 --- a/source/cMCLogger.cpp +++ b/source/cMCLogger.cpp @@ -22,7 +22,6 @@ cMCLogger* cMCLogger::GetInstance() cMCLogger::cMCLogger() { - m_CriticalSection = new cCriticalSection(); AString FileName; Printf(FileName, "LOG_%d.txt", (int)time(0) ); m_Log = new cLog(FileName); @@ -37,52 +36,66 @@ cMCLogger::cMCLogger() cMCLogger::cMCLogger( char* a_File ) { - m_CriticalSection = new cCriticalSection(); m_Log = new cLog( a_File ); } + + + + cMCLogger::~cMCLogger() { m_Log->Log("--- Stopped Log ---"); delete m_Log; - delete m_CriticalSection; - if( this == s_MCLogger ) - s_MCLogger = 0; + if (this == s_MCLogger) + s_MCLogger = NULL; } + + + + void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ ) { switch( a_LogType ) { - 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; + 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; } } + + + + void cMCLogger::Log(const char* a_Format, va_list a_ArgList) { - m_CriticalSection->Lock(); + cCSLock Lock(m_CriticalSection); SetColor( 0x7 ); // 0x7 is default grey color m_Log->Log( a_Format, a_ArgList ); - m_CriticalSection->Unlock(); + SetColor(0x07); // revert color back } + + + + void cMCLogger::Info(const char* a_Format, va_list a_ArgList) { - m_CriticalSection->Lock(); + cCSLock Lock(m_CriticalSection); // for( int i = 0; i < 16; i++) // { // for( int j = 0; j < 16; j++ ) @@ -95,25 +108,37 @@ void cMCLogger::Info(const char* a_Format, va_list a_ArgList) SetColor( 0xe ); // 0xe is yellow m_Log->Log( a_Format, a_ArgList ); - m_CriticalSection->Unlock(); + SetColor(0x07); // revert color back } + + + + void cMCLogger::Warn(const char* a_Format, va_list a_ArgList) { - m_CriticalSection->Lock(); + cCSLock Lock(m_CriticalSection); SetColor( 0xc ); // 0xc is red m_Log->Log( a_Format, a_ArgList ); - m_CriticalSection->Unlock(); + SetColor(0x07); // revert color back } + + + + void cMCLogger::Error(const char* a_Format, va_list a_ArgList) { - m_CriticalSection->Lock(); + cCSLock Lock(m_CriticalSection); SetColor( 0xc0 ); // 0xc0 is red bg and black text m_Log->Log( a_Format, a_ArgList ); - m_CriticalSection->Unlock(); + SetColor(0x07); // revert color back } + + + + void cMCLogger::SetColor( unsigned char a_Color ) { #ifdef _WIN32 @@ -125,6 +150,9 @@ void cMCLogger::SetColor( unsigned char a_Color ) } + + + ////////////////////////////////////////////////////////////////////////// // Global functions void LOG(const char* a_Format, ...) -- cgit v1.2.3