Started event handling

This commit is contained in:
Pax1601
2023-02-25 18:03:31 +01:00
parent abf5f40020
commit 93b1ac8f81
21 changed files with 140 additions and 310 deletions

View File

@@ -3,4 +3,4 @@
void DllExport log(const std::string& sMessage);
void DllExport log(const std::wstring& sMessage);
std::list<std::string> DllExport getLogs();
void DllExport logsToJSON(json::value& json);

View File

@@ -5,11 +5,12 @@
class Logger
{
public:
void Log(const string& sMessage);
void Log(const wstring& sMessage);
std::list<std::string> getLogs() { return m_logs; };
void log(const string& sMessage);
void log(const wstring& sMessage);
void toJSON(json::value& json);
static Logger* GetLogger();
private:
Logger();
Logger(const Logger&) {}; // copy constructor is private
@@ -20,6 +21,8 @@ private:
static ofstream m_Logfile;
static std::list<std::string> m_logs;
mutex mutexLock;
void Open();
void Close();
};

View File

@@ -6,15 +6,15 @@
void log(const string& message)
{
LOGGER->Log(message);
LOGGER->log(message);
}
void log(const wstring& message)
{
LOGGER->Log(message);
LOGGER->log(message);
}
std::list<std::string> getLogs()
void logsToJSON(json::value& json)
{
return LOGGER->getLogs();
LOGGER->toJSON(json);
}

View File

@@ -16,8 +16,7 @@ Logger* Logger::GetLogger()
if (m_pThis == NULL) {
m_pThis = new Logger();
std::filesystem::path dirPath = std::filesystem::temp_directory_path();
m_Logfile.open((dirPath.string() + m_sFileName).c_str(), ios::out | ios::app);
m_pThis->Log("**************************************************");
m_Logfile.open((dirPath.string() + m_sFileName).c_str(), ios::out);
}
return m_pThis;
}
@@ -33,8 +32,17 @@ void Logger::Close()
m_Logfile.close();
}
void Logger::Log(const string& message)
void Logger::toJSON(json::value& json)
{
lock_guard<mutex> guard(mutexLock);
int i = 0;
for (auto log : m_logs)
json[to_wstring(i++)] = json::value::string(to_wstring(log));
}
void Logger::log(const string& message)
{
lock_guard<mutex> guard(mutexLock);
Open();
m_Logfile << CurrentDateTime() << ":\t";
m_Logfile << message << "\n";
@@ -42,8 +50,9 @@ void Logger::Log(const string& message)
Close();
}
void Logger::Log(const wstring& message)
void Logger::log(const wstring& message)
{
lock_guard<mutex> guard(mutexLock);
Open();
m_Logfile << CurrentDateTime() << ":\t";
m_Logfile << to_string(message) << "\n";