mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-21 02:39:17 +00:00
Initial commit of current work on Prime World Editor
This commit is contained in:
78
Core/Log.cpp
Normal file
78
Core/Log.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <QMessageBox>
|
||||
#include <Common/StringUtil.h>
|
||||
|
||||
namespace Log
|
||||
{
|
||||
|
||||
static const std::string gskLogFilename = "primeworldeditor.log";
|
||||
FILE *gpLogFile = fopen(gskLogFilename.c_str(), "w");
|
||||
|
||||
void Write(const std::string& message)
|
||||
{
|
||||
|
||||
if (gpLogFile)
|
||||
{
|
||||
time_t RawTime;
|
||||
time(&RawTime);
|
||||
|
||||
tm *pTimeInfo = localtime(&RawTime);
|
||||
char Buffer[80];
|
||||
strftime(Buffer, 80, "[%H:%M:%S]", pTimeInfo);
|
||||
|
||||
fprintf(gpLogFile, "%s %s\n", Buffer, message.c_str());
|
||||
fflush(gpLogFile);
|
||||
}
|
||||
}
|
||||
|
||||
void Error(const std::string& message)
|
||||
{
|
||||
Write("ERROR: " + message);
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cout << "ERROR: " << message << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void Warning(const std::string& message)
|
||||
{
|
||||
Write("Warning: " + message);
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cout << "Warning: " << message << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void FileWrite(const std::string& filename, const std::string& message)
|
||||
{
|
||||
Write(filename + " : " + message);
|
||||
}
|
||||
|
||||
void FileWrite(const std::string& filename, unsigned long offset, const std::string& message)
|
||||
{
|
||||
Write(filename + " : " + StringUtil::ToHexString(offset) + " - " + message);
|
||||
}
|
||||
|
||||
void FileError(const std::string& filename, const std::string& message)
|
||||
{
|
||||
Error(filename + " : " + message);
|
||||
}
|
||||
|
||||
void FileError(const std::string &filename, unsigned long offset, const std::string &message)
|
||||
{
|
||||
Error(filename + " : " + StringUtil::ToHexString(offset) + " - " + message);
|
||||
}
|
||||
|
||||
void FileWarning(const std::string& filename, const std::string& message)
|
||||
{
|
||||
Warning(filename + " : " + message);
|
||||
}
|
||||
|
||||
void FileWarning(const std::string& filename, unsigned long offset, const std::string& message)
|
||||
{
|
||||
Warning(filename + " : " + StringUtil::ToHexString(offset) + " - " + message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user