#include "log.hpp" #include #include #include namespace t5de::log { // Each line is one appending write, so lines from several processes don't mix. void write(std::string_view line) { static const HANDLE file = [] { wchar_t temp[MAX_PATH + 1]; const DWORD length = GetTempPathW(MAX_PATH + 1, temp); if (length == 0 || length > MAX_PATH) { return INVALID_HANDLE_VALUE; } return CreateFileW((std::filesystem::path(temp) / L"t5de-renderer-process.log").c_str(), FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); }(); if (file != INVALID_HANDLE_VALUE) { const std::string text = std::format("{}: {}\n", GetCurrentProcessId(), line); DWORD written = 0; WriteFile(file, text.data(), static_cast(text.size()), &written, nullptr); } } } // namespace t5de::log