feat: write Dalamud.Boot logs to dalamud.boot.log

This commit is contained in:
goaaats 2022-05-29 17:25:29 +02:00
parent ad4f2db203
commit a7540d0fef
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
5 changed files with 39 additions and 14 deletions

View file

@ -9,9 +9,18 @@ HMODULE g_hModule;
HINSTANCE g_hGameInstance = GetModuleHandleW(nullptr); HINSTANCE g_hGameInstance = GetModuleHandleW(nullptr);
DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) { DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
logging::log_file.open(utils::get_env<std::wstring>("DALAMUD_BOOT_LOGFILE"), std::ios_base::out | std::ios_base::app);
if (bootconfig::is_show_console()) if (bootconfig::is_show_console())
ConsoleSetup(L"Dalamud Boot"); ConsoleSetup(L"Dalamud Boot");
if (!logging::log_file) {
logging::print<logging::E>("Couldn't open log file!");
}
logging::print<logging::I>("Dalamud.Boot Injectable, (c) 2021 XIVLauncher Contributors");
logging::print<logging::I>("Built at: " __DATE__ "@" __TIME__);
if (bootconfig::is_wait_messagebox()) if (bootconfig::is_wait_messagebox())
MessageBoxW(nullptr, L"Press OK to continue", L"Dalamud Boot", MB_OK); MessageBoxW(nullptr, L"Press OK to continue", L"Dalamud Boot", MB_OK);
@ -22,9 +31,6 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
logging::print<logging::W>("Error: {}", e.what()); logging::print<logging::W>("Error: {}", e.what());
} }
logging::print<logging::I>("Dalamud.Boot Injectable, (c) 2021 XIVLauncher Contributors");
logging::print<logging::I>("Built at : " __DATE__ "@" __TIME__);
if (bootconfig::is_wait_debugger()) { if (bootconfig::is_wait_debugger()) {
logging::print<logging::I>("Waiting for debugger to attach..."); logging::print<logging::I>("Waiting for debugger to attach...");
while (!IsDebuggerPresent()) while (!IsDebuggerPresent())
@ -87,6 +93,7 @@ BOOL APIENTRY DllMain(const HMODULE hModule, const DWORD dwReason, LPVOID lpRese
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
xivfixes::apply_all(false); xivfixes::apply_all(false);
veh::remove_handler(); veh::remove_handler();
//logging::log_file.close();
break; break;
} }
return TRUE; return TRUE;

View file

@ -32,4 +32,10 @@ void logging::print(Level level, const char* s) {
DWORD wr; DWORD wr;
WriteFile(GetStdHandle(STD_ERROR_HANDLE), &estr[0], static_cast<DWORD>(estr.size()), &wr, nullptr); WriteFile(GetStdHandle(STD_ERROR_HANDLE), &estr[0], static_cast<DWORD>(estr.size()), &wr, nullptr);
if (log_file.is_open())
{
log_file << estr;
log_file.flush();
}
} }

View file

@ -3,10 +3,13 @@
#include <format> #include <format>
#include <numeric> #include <numeric>
#include <string> #include <string>
#include <fstream>
#include "unicode.h" #include "unicode.h"
namespace logging { namespace logging {
inline std::ofstream log_file;
enum Level : int { enum Level : int {
Verbose = 0, Verbose = 0,
V = 0, V = 0,

View file

@ -101,6 +101,19 @@ namespace Dalamud.Injector
} }
} }
private static string GetLogPath(string filename)
{
var baseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
#if DEBUG
var logPath = Path.Combine(baseDirectory, $"{filename}.log");
#else
var logPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.injector.log");
#endif
return logPath;
}
private static void Init(List<string> args) private static void Init(List<string> args)
{ {
InitUnhandledException(args); InitUnhandledException(args);
@ -161,14 +174,6 @@ namespace Dalamud.Injector
private static void InitLogging() private static void InitLogging()
{ {
var baseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
#if DEBUG
var logPath = Path.Combine(baseDirectory, "dalamud.injector.log");
#else
var logPath = Path.Combine(baseDirectory, "..", "..", "..", "dalamud.injector.log");
#endif
var levelSwitch = new LoggingLevelSwitch(); var levelSwitch = new LoggingLevelSwitch();
#if DEBUG #if DEBUG
@ -177,6 +182,10 @@ namespace Dalamud.Injector
levelSwitch.MinimumLevel = LogEventLevel.Information; levelSwitch.MinimumLevel = LogEventLevel.Information;
#endif #endif
var logPath = GetLogPath("dalamud.injector");
Environment.SetEnvironmentVariable("DALAMUD_BOOT_LOGFILE", GetLogPath("dalamud.boot"));
CullLogFile(logPath, 1 * 1024 * 1024); CullLogFile(logPath, 1 * 1024 * 1024);
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()

View file

@ -73,9 +73,9 @@ int InitializeClrAndGetEntryPoint(
// =========================================================================== // // =========================================================================== //
logging::print<logging::I>(L"with dotnet_path: %s", dotnet_path); logging::print<logging::I>(L"with dotnet_path: {}", dotnet_path);
logging::print<logging::I>(L"with config_path: %s", runtimeconfig_path.c_str()); logging::print<logging::I>(L"with config_path: {}", runtimeconfig_path.c_str());
logging::print<logging::I>(L"with module_path: %s", module_path.c_str()); logging::print<logging::I>(L"with module_path: {}", module_path.c_str());
if (!std::filesystem::exists(dotnet_path)) if (!std::filesystem::exists(dotnet_path))
{ {