feat: add log test

This commit is contained in:
2026-05-07 01:25:41 -03:00
parent 7595e8f19e
commit 102107a583
+65
View File
@@ -0,0 +1,65 @@
#include "tests.h"
#include <seallib/log.h>
#include <iostream>
/*
win32 console stuff
*/
#ifdef _WIN32
#define _AMD64_
#include <consoleapi.h>
#include <processenv.h>
// from: WinBase.h
#define STD_OUTPUT_HANDLE ((DWORD) - 11)
void createAndSetupConsole()
{
FILE* pstdout = stdout;
AllocConsole();
freopen_s(&pstdout, "CONOUT$", "w", stdout);
DWORD conMode = 0;
GetConsoleMode(pstdout, &conMode);
conMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(pstdout, conMode);
}
#endif
/*
test impl
*/
using namespace seallib;
class TestLogSink : public ILogSink
{
public:
virtual void receiveLog(LogType type, std::string_view loggerName, std::string_view msg) override
{
std::cout << seallib::getLogTypeColor(type) << "[" << seallib::getLogTypeName(type) << "]"
<< "\x1b[0m " << msg << std::endl;
}
};
class LogTest : ITest
{
public:
LogTest() : ITest() {};
virtual void run() override
{
#ifdef _WIN32
createAndSetupConsole();
#endif
Logger log("TestLogger");
log.addSink(std::make_shared<TestLogSink>());
log.verbose("verbose log");
log.info("info log");
log.warning("warning log");
log.error("error log");
}
};
static LogTest g_logTest;