feat: add logger
This commit is contained in:
39
L2BotDll/Logger/ChatLogChannel.h
Normal file
39
L2BotDll/Logger/ChatLogChannel.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Enums/ChatChannelEnum.h"
|
||||
#include "Domain/Events/ChatMessageCreatedEvent.h"
|
||||
#include "Domain/Logger/LogChannel.h"
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
class ChatLogChannel : public Logger::LogChannel
|
||||
{
|
||||
public:
|
||||
ChatLogChannel(const Enums::ChatChannelEnum chatChannel, const std::vector<Logger::LogLevel> levels) :
|
||||
Logger::LogChannel(levels),
|
||||
m_ChatChannel(chatChannel)
|
||||
{
|
||||
};
|
||||
virtual ~ChatLogChannel() = default;
|
||||
|
||||
protected:
|
||||
void DoSendToChannel(const std::wstring& logEntry) override
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
|
||||
Events::ChatMessageCreatedEvent
|
||||
{
|
||||
DTO::ChatMessageData
|
||||
{
|
||||
0,
|
||||
static_cast<uint8_t>(m_ChatChannel),
|
||||
L"",
|
||||
GetCurrentDateTime() + logEntry
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const Enums::ChatChannelEnum m_ChatChannel;
|
||||
};
|
30
L2BotDll/Logger/FileLogChannel.h
Normal file
30
L2BotDll/Logger/FileLogChannel.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <fstream>
|
||||
#include "Domain/Logger/LogChannel.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
class FileLogChannel : public Logger::LogChannel
|
||||
{
|
||||
public:
|
||||
FileLogChannel(const std::wstring& path, const std::vector<Logger::LogLevel> levels) :
|
||||
m_FileStream(path.c_str(), std::wofstream::app),
|
||||
Logger::LogChannel(levels)
|
||||
{
|
||||
};
|
||||
virtual ~FileLogChannel()
|
||||
{
|
||||
m_FileStream.close();
|
||||
}
|
||||
|
||||
protected:
|
||||
void DoSendToChannel(const std::wstring& logEntry) override
|
||||
{
|
||||
m_FileStream << GetCurrentDateTime() << logEntry << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::wofstream m_FileStream;
|
||||
};
|
19
L2BotDll/Logger/OutputDebugLogChannel.h
Normal file
19
L2BotDll/Logger/OutputDebugLogChannel.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include "Domain/Logger/LogChannel.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
class OutputDebugLogChannel : public Logger::LogChannel
|
||||
{
|
||||
public:
|
||||
OutputDebugLogChannel(const std::vector<Logger::LogLevel> levels) : Logger::LogChannel(levels) {};
|
||||
virtual ~OutputDebugLogChannel() = default;
|
||||
|
||||
protected:
|
||||
void DoSendToChannel(const std::wstring& logEntry) override
|
||||
{
|
||||
OutputDebugStringW((GetCurrentDateTime() + logEntry).c_str());
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user