Skip to content

Commit 9de6abd

Browse files
committed
makes logging asynchronous
1 parent d7bc1c6 commit 9de6abd

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/dllmain.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ void Main(HINSTANCE hinstDLL)
2525

2626
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
2727
{
28-
switch (fdwReason)
28+
if (fdwReason == DLL_PROCESS_ATTACH)
2929
{
30-
case DLL_PROCESS_ATTACH:
31-
{
32-
Main(hinstDLL);
33-
break;
34-
}
35-
36-
case DLL_THREAD_ATTACH:
37-
case DLL_THREAD_DETACH:
38-
case DLL_PROCESS_DETACH:
39-
break;
30+
Main(hinstDLL);
31+
}
32+
else if (fdwReason == DLL_PROCESS_DETACH)
33+
{
34+
spdlog::shutdown();
4035
}
4136

4237
return TRUE;

src/m2fix.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class M2Fix
132132
auto path = M2Hook::GetInstance().ModuleLocation().parent_path();
133133

134134
try {
135-
auto logger = spdlog::basic_logger_mt(FixName(), (path / LogFile()).string(), true);
135+
spdlog::init_thread_pool(8192, 1);
136+
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>((path / LogFile()).string(), true);
137+
auto logger = std::make_shared<spdlog::async_logger>(FixName(), sink, spdlog::thread_pool(), spdlog::async_overflow_policy::block);
136138
spdlog::set_default_logger(logger);
137139
}
138140
catch (const spdlog::spdlog_ex & ex) {

src/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ using namespace StdExt;
5555

5656
#include "inipp.h"
5757
#include "spdlog.h"
58+
#include "async.h"
5859
#include "spdlog/sinks/basic_file_sink.h"
5960
#include "spdlog/sinks/stdout_sinks.h"
6061
#include "spdlog/sinks/wincolor_sink.h"

0 commit comments

Comments
 (0)