aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-10-27 00:52:51 +0200
committerShauren <shauren.trinity@gmail.com>2025-10-26 23:37:15 +0100
commit62ba3d8b4ee2e2acd0d574600137dbdd65b92f50 (patch)
treebf329087812f32eeea1b07b78bf27c4a697badbf
parente8252152cfff5fad65fa0ba8f857d85dc9c7dbf6 (diff)
Tools/mmaps_generator: Enable async console logging
-rw-r--r--src/common/Logging/Log.cpp8
-rw-r--r--src/common/Logging/Log.h1
-rw-r--r--src/tools/mmaps_generator/PathGenerator.cpp20
3 files changed, 25 insertions, 4 deletions
diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp
index 4514fbabd1a..6ec978c3206 100644
--- a/src/common/Logging/Log.cpp
+++ b/src/common/Logging/Log.cpp
@@ -367,13 +367,17 @@ 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()
diff --git a/src/common/Logging/Log.h b/src/common/Logging/Log.h
index 17e0421d422..5621ec67f86 100644
--- a/src/common/Logging/Log.h
+++ b/src/common/Logging/Log.h
@@ -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();
diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp
index 0830c977886..b090678e83a 100644
--- a/src/tools/mmaps_generator/PathGenerator.cpp
+++ b/src/tools/mmaps_generator/PathGenerator.cpp
@@ -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;
}