Tools/mmaps_generator: Enable async console logging

This commit is contained in:
Shauren
2025-10-27 00:52:51 +02:00
parent e8252152cf
commit 62ba3d8b4e
3 changed files with 25 additions and 4 deletions

View File

@@ -366,14 +366,18 @@ Log* Log::instance() noexcept
}
void Log::Initialize(Trinity::Asio::IoContext* ioContext)
{
SetAsynchronous(ioContext);
LoadFromConfig();
}
void Log::SetAsynchronous(Trinity::Asio::IoContext* ioContext)
{
if (ioContext)
{
_ioContext = ioContext;
_strand = new Trinity::Asio::Strand(*ioContext);
}
LoadFromConfig();
}
void Log::SetSynchronous()

View File

@@ -63,6 +63,7 @@ class TC_COMMON_API Log
static Log* instance() noexcept;
void Initialize(Trinity::Asio::IoContext* ioContext);
void SetAsynchronous(Trinity::Asio::IoContext* ioContext);
void SetSynchronous(); // Not threadsafe - should only be called from main() after all threads are joined
void LoadFromConfig();
void Close();

View File

@@ -19,9 +19,11 @@
#include "DB2FileLoader.h"
#include "DB2FileSystemSource.h"
#include "ExtractorDB2LoadInfo.h"
#include "IoContext.h"
#include "Locales.h"
#include "Log.h"
#include "MapBuilder.h"
#include "Memory.h"
#include "PathCommon.h"
#include "Timer.h"
#include "Util.h"
@@ -71,10 +73,12 @@ namespace MMAP
}
}
void SetupLogging()
void SetupLogging(Trinity::Asio::IoContext* ioContext)
{
Log* log = sLog;
log->SetAsynchronous(ioContext);
log->CreateAppenderFromConfigLine("Appender.Console", "1,2,0"); // APPENDER_CONSOLE | LOG_LEVEL_DEBUG | APPENDER_FLAGS_NONE
log->CreateLoggerFromConfigLine("Logger.root", "2,Console"); // LOG_LEVEL_DEBUG | Console appender
log->CreateLoggerFromConfigLine("Logger.tool.mmapgen", "2,Console"); // LOG_LEVEL_DEBUG | Console appender
@@ -411,7 +415,18 @@ int main(int argc, char** argv)
Trinity::Locale::Init();
SetupLogging();
Trinity::Asio::IoContext ioContext(1);
SetupLogging(&ioContext);
std::thread loggingThread;
auto workGuard = std::pair(
Trinity::make_unique_ptr_with_deleter(&loggingThread, [](std::thread* thread) { thread->join(); }),
boost::asio::make_work_guard(ioContext.get_executor())
);
loggingThread = std::thread([](Trinity::Asio::IoContext* context) { context->run(); }, &ioContext);
Trinity::Banner::Show("MMAP generator", [](char const* text) { TC_LOG_INFO("tool.mmapgen", "{}", text); }, nullptr);
@@ -472,6 +487,7 @@ int main(int argc, char** argv)
if (!silent)
TC_LOG_INFO("tool.mmapgen", "Finished. MMAPS were built in {}", secsToTimeString(GetMSTimeDiffToNow(start) / 1000));
return 0;
}