<commit_before>
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include <time.h>
#include "Log.h"





cMCLogger * cMCLogger::s_MCLogger = NULL;

#ifdef _WIN32
	HANDLE g_Console = GetStdHandle(STD_OUTPUT_HANDLE);
#endif




cMCLogger* cMCLogger::GetInstance()
{
	return s_MCLogger;
}





cMCLogger::cMCLogger(void)
{
	AString FileName;
	Printf(FileName, "LOG_%d.txt", (int)time(NULL));
	m_Log = new cLog(FileName);
	m_Log->Log("--- Started Log ---");

	s_MCLogger = this;
}





cMCLogger::cMCLogger(const AString & a_FileName)
{
	m_Log = new cLog(a_FileName);
}





cMCLogger::~cMCLogger()
{
	m_Log->Log("--- Stopped Log ---");
	delete m_Log;
	if (this == s_MCLogger)
		s_MCLogger = NULL;
}





void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
{
	switch( a_LogType )
	{
		case 0:
			LOG("%s", a_Text);
			break;
		case 1:
			LOGINFO("%s", a_Text);
			break;
		case 2:
			LOGWARN("%s", a_Text);
			break;
		case 3:
			LOGERROR("%s", a_Text);
			break;
		default:
			LOG("(#%d#: %s", a_LogType, a_Text);
			break;
	}
}





void cMCLogger::Log(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csGrayOnBlack);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::Info(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csYellowOnBlack);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::Warn(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csRedOnBlack);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::Error(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csBlackOnRed);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::SetColor(eColorScheme a_Scheme)
{
	#ifdef _WIN32
		WORD Attrib = 0x07;  // by default, gray on black
		switch (a_Scheme)
		{
			case csGrayOnBlack:   Attrib = 0x07; break;
			case csYellowOnBlack: Attrib = 0x0e; break;
			case csRedOnBlack:    Attrib = 0x0c; break;
			case csBlackOnRed:    Attrib = 0xc0; break;
			default: ASSERT(!"Unhandled color scheme");
		}
		SetConsoleTextAttribute(g_Console, Attrib);
	#elif defined(__linux) && !defined(ANDROID_NDK)
		switch (a_Scheme)
		{
			case csGrayOnBlack:   puts("\x1b[0m");    break;
			case csYellowOnBlack: puts("\x1b[33;1m"); break;
			case csRedOnBlack:    puts("\x1b[31;1m"); break;
			case csBlackOnRed:    puts("\x1b[7;31;1m"); break;
			default: ASSERT(!"Unhandled color scheme");
		}
	#endif
}





//////////////////////////////////////////////////////////////////////////
// Global functions
void LOG(const char* a_Format, ...)<commit_msg>Use printf() instead of puts().<commit_after>
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include <time.h>
#include "Log.h"





cMCLogger * cMCLogger::s_MCLogger = NULL;

#ifdef _WIN32
	HANDLE g_Console = GetStdHandle(STD_OUTPUT_HANDLE);
#endif




cMCLogger* cMCLogger::GetInstance()
{
	return s_MCLogger;
}





cMCLogger::cMCLogger(void)
{
	AString FileName;
	Printf(FileName, "LOG_%d.txt", (int)time(NULL));
	m_Log = new cLog(FileName);
	m_Log->Log("--- Started Log ---");

	s_MCLogger = this;
}





cMCLogger::cMCLogger(const AString & a_FileName)
{
	m_Log = new cLog(a_FileName);
}





cMCLogger::~cMCLogger()
{
	m_Log->Log("--- Stopped Log ---");
	delete m_Log;
	if (this == s_MCLogger)
		s_MCLogger = NULL;
}





void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
{
	switch( a_LogType )
	{
		case 0:
			LOG("%s", a_Text);
			break;
		case 1:
			LOGINFO("%s", a_Text);
			break;
		case 2:
			LOGWARN("%s", a_Text);
			break;
		case 3:
			LOGERROR("%s", a_Text);
			break;
		default:
			LOG("(#%d#: %s", a_LogType, a_Text);
			break;
	}
}





void cMCLogger::Log(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csGrayOnBlack);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::Info(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csYellowOnBlack);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::Warn(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csRedOnBlack);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::Error(const char * a_Format, va_list a_ArgList)
{
	cCSLock Lock(m_CriticalSection);
	SetColor(csBlackOnRed);
	m_Log->Log(a_Format, a_ArgList);
}





void cMCLogger::SetColor(eColorScheme a_Scheme)
{
	#ifdef _WIN32
		WORD Attrib = 0x07;  // by default, gray on black
		switch (a_Scheme)
		{
			case csGrayOnBlack:   Attrib = 0x07; break;
			case csYellowOnBlack: Attrib = 0x0e; break;
			case csRedOnBlack:    Attrib = 0x0c; break;
			case csBlackOnRed:    Attrib = 0xc0; break;
			default: ASSERT(!"Unhandled color scheme");
		}
		SetConsoleTextAttribute(g_Console, Attrib);
	#elif defined(__linux) && !defined(ANDROID_NDK)
		switch (a_Scheme)
		{
			case csGrayOnBlack:   printf("\x1b[0m");    break;
			case csYellowOnBlack: printf("\x1b[33;1m"); break;
			case csRedOnBlack:    printf("\x1b[31;1m"); break;
			case csBlackOnRed:    printf("\x1b[7;31;1m"); break;
			default: ASSERT(!"Unhandled color scheme");
		}
	#endif
}





//////////////////////////////////////////////////////////////////////////
// Global functions
void LOG(const char* a_Format, ...)
{'fraction_non_alphanumeric': 0.16734769687964338, 'fraction_numerical': 0.01337295690936107, 'mean_word_length': 3.6025641025641026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5131694', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2163, 'n_words': 434}