1#include "server_logger.h"
2
3#include "server.h"
4
5CServerLogger::CServerLogger(CServer *pServer) :
6 m_pServer(pServer),
7 m_MainThread(std::this_thread::get_id())
8{
9 dbg_assert(pServer != nullptr, "server pointer must not be null");
10}
11
12void CServerLogger::Log(const CLogMessage *pMessage)
13{
14 if(m_Filter.Filters(pMessage))
15 {
16 return;
17 }
18 m_PendingLock.lock();
19 if(m_MainThread == std::this_thread::get_id())
20 {
21 if(!m_vPending.empty())
22 {
23 if(m_pServer)
24 {
25 for(const auto &Message : m_vPending)
26 {
27 m_pServer->SendLogLine(pMessage: &Message);
28 }
29 }
30 m_vPending.clear();
31 }
32 m_PendingLock.unlock();
33 if(m_pServer)
34 m_pServer->SendLogLine(pMessage);
35 }
36 else
37 {
38 m_vPending.push_back(x: *pMessage);
39 m_PendingLock.unlock();
40 }
41}
42
43void CServerLogger::OnServerDeletion()
44{
45 dbg_assert(m_MainThread == std::this_thread::get_id(), "CServerLogger::OnServerDeletion not called from the main thread");
46 m_pServer = nullptr;
47}
48