summaryrefslogtreecommitdiffstats
path: root/source/cMCLogger.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-02 08:47:19 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-02 08:47:19 +0100
commit865216b15a4cfb836dddcb9bf66532b4f46497a3 (patch)
tree789c307051468c4aa0bf030e417fff03cac3a2a1 /source/cMCLogger.cpp
parentRewritten cAuthenticator to make use of the new cIsThread architecture - now authentication runs in a single separate thread for all clients; (diff)
downloadcuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.tar
cuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.tar.gz
cuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.tar.bz2
cuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.tar.lz
cuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.tar.xz
cuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.tar.zst
cuberite-865216b15a4cfb836dddcb9bf66532b4f46497a3.zip
Diffstat (limited to '')
-rw-r--r--source/cMCLogger.cpp84
1 files changed, 56 insertions, 28 deletions
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, ...)