feat(inject): Use async log sink for logging

Solves similar issues with the old games not using
the AVS logging system (because there is none).

Threads calling the log functions are still logging
using OutputDebugStr, but the dispatching in the
debugger module in inject hands those messages
off to the async log sink which avoids blocking
the calling thread (for long).

We want to keep this feature around as there are
several games actually having non-removed
OutputDebugStr calls which can provide some
useful debugging information.

Furthermore, neutral hooks only using DllMain
and not the bemanitools API can still channel
log messages this way to bemanitools’s logging
system (though less efficiently than calling it
directly).

Further changes to existing hooks will be applied
to migrate their logger usage to using the logger
directly through the bemanitools API.
This commit is contained in:
icex2 2024-08-15 11:34:31 +02:00
parent 8bb8c3364e
commit 27e9f8dea8

View File

@ -53,25 +53,12 @@ static void _inject_log_header()
void _inject_log_init(
const char *log_file_path, enum core_log_bt_log_level level)
{
core_log_sink_t sinks[2];
core_log_sink_t sink_composed;
core_log_sink_t sink_mutex;
if (log_file_path) {
core_log_sink_std_out_open(true, &sinks[0]);
core_log_sink_file_open(log_file_path, false, true, 10, &sinks[1]);
core_log_sink_list_open(sinks, 2, &sink_composed);
core_log_bt_ext_init_async_with_stderr_and_file(log_file_path, false, true, 10);
} else {
core_log_sink_std_out_open(true, &sink_composed);
core_log_bt_ext_init_async_with_stderr();
}
// Different threads logging the same destination, e.g. debugger thread,
// main thread
// TODO this needs to be de-coupled with async logging to fix latency
// issues for any game related threads logging
core_log_sink_mutex_open(&sink_composed, &sink_mutex);
core_log_bt_init(&sink_mutex);
core_log_bt_core_api_set();
core_log_bt_level_set(level);
@ -217,6 +204,8 @@ int main(int argc, char **argv)
goto init_options_fail;
}
core_thread_crt_core_api_set();
// TODO expose log level
_inject_log_init(
strlen(options.log_file) > 0 ? options.log_file : NULL,
@ -225,8 +214,6 @@ int main(int argc, char **argv)
_inject_log_header();
os_version_log();
core_thread_crt_core_api_set();
signal_exception_handler_init();
// Cleanup remote process on CTRL+C
signal_register_shutdown_handler(signal_shutdown_handler);