*
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include "CLog.h"
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
CLog::CLog()
|
||||
:logToConsole(true)
|
||||
{
|
||||
hLogFile = CreateFile(String(_text("engine_log.txt")).c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
SetFilePointer(hLogFile,0,NULL, FILE_END);
|
||||
Write(String(_text("\nLogging started!")).c_str());
|
||||
}
|
||||
void CLog::LogToConsole(bool condition)
|
||||
{
|
||||
logToConsole = condition;
|
||||
}
|
||||
CLog::~CLog()
|
||||
{
|
||||
if(hLogFile)
|
||||
{
|
||||
Write(_text("Closing log"));
|
||||
CloseHandle(hLogFile);
|
||||
}
|
||||
}
|
||||
void CLog::Write(const String& message)
|
||||
{
|
||||
DWORD nb = 0;
|
||||
WriteFile(hLogFile, message.c_str(), string_size(message), &nb, NULL);
|
||||
WriteFile(hLogFile, L"\n", 1, &nb, NULL);
|
||||
|
||||
if(logToConsole)
|
||||
printf("Log: %s\n", message.c_str());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user